我的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'
我该如何解决这个问题?
答案 0 :(得分:1)
resultSheet.setSheetPassword(PASSWORD, HashAlgorithm.md5);