java - Apache poi 表密码不起作用

标签 java excel

我已将 Excel 文件表锁定为

XSSFSheet resultSheet = ((XSSFSheet) getResultSheet(workbook));
resultSheet.getCTWorksheet().getSheetProtection().setPassword(PASSWORD.getBytes());
resultSheet.lockSelectUnlockedCells(false);
resultSheet.lockSelectLockedCells(true);
resultSheet.lockFormatCells(true);
resultSheet.lockFormatColumns(true);
resultSheet.lockFormatRows(true);
resultSheet.lockInsertColumns(true);
resultSheet.lockInsertRows(true);
resultSheet.lockInsertHyperlinks(true);
resultSheet.lockDeleteColumns(true);
resultSheet.lockDeleteRows(true);
resultSheet.lockSort(true);
resultSheet.lockAutoFilter(true);
resultSheet.lockPivotTables(true);
resultSheet.lockObjects(true);
resultSheet.lockScenarios(true);
resultSheet.enableLocking();

此代码示例保护工作表,但无需密码即可解锁。我也尝试过 CTSheetProtection ctSheetProtection = CTSheetProtection.Factory.newInstance(); 但不成功。 Apache poi 版本是

compile ('org.apache.poi:poi-ooxml:3.15') {
    exclude module: 'poi-ooxml-schemas'
}
compile 'org.apache.poi:ooxml-schemas:1.3'

我该如何解决这个问题?

最佳答案

resultSheet.setSheetPassword(PASSWORD, HashAlgorithm.md5);

关于java - Apache poi 表密码不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45097889/

相关文章:

c# - 将 GridView 导出到 excel #2

excel - 如何使 Excel 成为手动输入的有效关系数据源?

java - 在 Java 中使用 + 连接字符串

java - 单击 Android 应用程序中的按钮时导航失败,错误为 "Unfortunately, ' myapp' 已停止”

c# - 如何使用 C# 的 OLEDB 在 Excel 中执行此 "select * from [sheet1$] where column is L"?

excel - 不使用 .activate 在不同工作簿之间切换

excel - 在线存储 Power Query 自定义函数(Github 等..)并调用它

java - JMockit 捕获并替换接口(interface)方法逻辑

java - 如何在java中为列表分配对象类型?

java正则表达式查找和替换