Java Apache poi表密码不起作用
我已将excel文件表锁定为Java Apache poi表密码不起作用,java,excel,Java,Excel,我已将excel文件表锁定为 XSSFSheet resultSheet = ((XSSFSheet) getResultSheet(workbook)); resultSheet.getCTWorksheet().getSheetProtection().setPassword(PASSWORD.getBytes()); resultSheet.lockSelectUnlockedCells(false); resultSheet.lockSelectLockedCells(true); re
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()代码>
但是没有成功。
ApachePOI版本是
compile ('org.apache.poi:poi-ooxml:3.15') {
exclude module: 'poi-ooxml-schemas'
}
compile 'org.apache.poi:ooxml-schemas:1.3'
如何解决这个问题?我使用的是POI 3.17,但它不起作用:工作表可以在没有密码提示的情况下解锁。。。
resultSheet.setSheetPassword(PASSWORD, HashAlgorithm.md5);