获取使用Apache POI Excel工作簿密码 [英] Get the excel workbook password using Apache POI
问题描述
我想读取数据的Excel表格中,我能够获得数据,并使用读 HSSFWorkbook
一切运作良好,我能够获得数据。
我已经为工作簿设置了密码,在Excel工作表手动保护工作簿
来ABCXYZ,并在打开的Excel文件,它会问我密码,只在正确的密码后,它让我在写入或读取Excel文件。
我的问题是如何在Java程序中获得此密码ABCXYZ。
HSSFWorkbook WB =新HSSFWorkbook(InputStream的);
wb.isWriteProtected(); - >这返回false。
据我所知,你可以使用:
(在Excel 2003中)
POIFSFileSystem PFS =新POIFSFileSystem(新的FileInputStream(yourexcelfile.xls));
Biff8EncryptionKey.setCurrentUserPassword(ABCXYZ);
HSSFWorkbook WB =新HSSFWorkbook(PFS);
(在Excel 2007中)
POIFSFileSystem PFS = newPOIFSFileSystem(POIDataSamples.getPOIFSInstance()openResourceAsStream(yourexcelfile.xlsx)。);
EncryptionInfo encInfo =新EncryptionInfo(PFS);
解密解密=新解密(encInfo);
decryptor.verifyPassword(ABCXYZ);
XSSFWorkbook WB =新XSSFWorkbook(decryptor.getDataStream(PFS));
希望它帮助!
I am trying to read an excel sheet of data, I am able to get the data and read it using HSSFWorkbook
Everything works well, I am able to get the data.
I have set a password for the workbook, manually in the excel sheet Protect Workbook
to "ABCXYZ" and while opening the excel file it will ask me the password and only after the password in correct it lets me in to write or read the excel file.
My question is how to get this password "ABCXYZ" in the java program.
HSSFWorkbook wb = new HSSFWorkbook(inputStream);
wb.isWriteProtected();--> This returns false.
As far as I know, you can use:
(in Excel 2003)
POIFSFileSystem pfs = new POIFSFileSystem(new FileInputStream("yourexcelfile.xls"));
Biff8EncryptionKey.setCurrentUserPassword("ABCXYZ");
HSSFWorkbook wb = new HSSFWorkbook(pfs);
(in Excel 2007)
POIFSFileSystem pfs = newPOIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("yourexcelfile.xlsx"));
EncryptionInfo encInfo = new EncryptionInfo(pfs);
Decryptor decryptor = new Decryptor(encInfo);
decryptor.verifyPassword("ABCXYZ");
XSSFWorkbook wb = new XSSFWorkbook(decryptor.getDataStream(pfs));
Hope it helps!
这篇关于获取使用Apache POI Excel工作簿密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!