HSSFWorkbook 中的结构锁定可能吗? [英] Structure lock in HSSFWorkbook possible?
问题描述
在 POI XSSFWorkbook 中,存在可以保护 Excel 工作簿的方法 lockStructure 和 lockWindows.(excel menue 中的Review->Protect Workbook..."下的功能)
这些方法的功能类似于 Excel 中的 Workbook.protect 方法:https://docs.microsoft.com/en-us/office/vba/api/excel.workbook.protect
有没有办法在 HSSFWorkbook 中启用这种保护?
我已经尝试过 HSSFWorkbook 中的 writeProtectWorkbook 方法,但它与 XSSFWorkbook 中的方法不同.方法 writeProtectWorkbook 设置打开的密码.
可能我必须修改工作表保护块"这在第 200 页的第 5.82 节中进行了描述:http://www.openoffice.org/sc/excelfileformat.pdf
有谁知道我如何通过 POI 获得这个块?
我使用 poi:5.0.0.
In the POI XSSFWorkbook, the methods lockStructure and lockWindows exist with which an Excel Workbook can be protected. (Function in excel menue under "Review->Protect Workbook...")
The function of these methods is analogous to the Workbook.protect method in Excel:
https://docs.microsoft.com/en-us/office/vba/api/excel.workbook.protect
Is there any way to enable this protection in a HSSFWorkbook?
I have already tried the writeProtectWorkbook method from HSSFWorkbook, but it does not do the same as the methods in the XSSFWorkbook. The method writeProtectWorkbook sets an open password.
Probably I have to modify the "worksheet protection block" which is described in section 5.82 here on page 200: http://www.openoffice.org/sc/excelfileformat.pdf
Does anyone know how I can get this block with POI?
I use poi:5.0.0.
推荐答案
我发现了如何启用工作簿保护.在InternalWorkbook 中有一个记录列表.它们包含记录类型ProtectRecord、WindowProtectRecord 和PasswordRecord.通过这些,您可以设置工作簿保护:
I found out myself how to enable Workbook Protection. In the InternalWorkbook there is a list of records. These contain the record types ProtectRecord, WindowProtectRecord and PasswordRecord. With these you can set the Workbook Protection:
List<Record> records = ((HSSFWorkbook) wb).getInternalWorkbook().getRecords();
for (Record record : records) {
if (record instanceof ProtectRecord) {
((ProtectRecord) record).setProtect(true);
} else if (record instanceof WindowProtectRecord) {
((WindowProtectRecord) record).setProtect(true);
} else if (record instanceof PasswordRecord) {
((PasswordRecord) record).setPassword((short) CryptoFunctions.createXorVerifier1("password"));
}
}
这篇关于HSSFWorkbook 中的结构锁定可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!