The ways to read Excel 2003(xls) and Excel 2007(xlsx) files are different .
1 2003(xls)
Please use the Biff8EncryptionKey Class to specify the password,and POI
can automatically validate
whether the specied password is right. and open the excel file.
Example (code)
POIFSFileSystem pois = new POIFSFileSystem(new
FileInputStream("test.xls"));
Biff8EncryptionKey.setCurrentUserPassword("password");
HSSFWorkbook book = new HSSFWorkbook(pois);
The method of setCurrentUserPassword is thread safe.
2 2007(xlsx)
The difference with 2007's way is that password validate is not
automatical,
Example (code) -> the Junit test code from POI source package
(DecryptorTest.java)
POIFSFileSystem fs = new
POIFSFileSystem(POIDataSamples.getPOIFSInstance().openResourceAsStream("protect.xlsx"));
EncryptionInfo info = new EncryptionInfo(fs);
Decryptor d = new Decryptor(info);
d.verifyPassword("password");
d.getDataStream(fs); -> inputStream
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/support-for-reading-password-of-excel-tp4338009p4340476.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]