0

我正在尝试使用 Hssf 工作簿和 Biff8EncryptionKey 设置密码。但我没有得到任何响应。

 HSSFWorkbook writeWorkbook = new HSSFWorkbook();
       Biff8EncryptionKey.setCurrentUserPassword("pass");
       NPOIFSFileSystem fs = new NPOIFSFileSystem(new File("C:\\Users\\Visaws\\Desktop\\test4.xls"), true);
4

1 回答 1

0

请参考以下代码

private boolean importTables(InputStream stream, String fileName) throws Exception {
Workbook workbook;
if (fileName.toLowerCase().endsWith(".xls")) {
if (!TextUtils.isEmpty(decryptKey)) {
Biff8EncryptionKey.setCurrentUserPassword("1234567");
}
workbook = new HSSFWorkbook(stream);
} else {
throw new UnsupportedOperationException("Unsupported file format!");
}
stream.close();
int sheetNumber = workbook.getNumberOfSheets();
for (int i = 0; i < sheetNumber; i++) {
createTable(workbook.getSheetAt(i));
}
database.close();
return true;
}
于 2019-08-23T10:14:09.303 回答