Nick Thanks for your quick reply, this works very nicely indeed.
I'm afraid I have a couple more related questions... Obviously this is working by loading the file into memory and some of the files I received are 50, 80 + MB in size. Therefore I would like to use the SXSSF of 3.8 (beta) and set the window size quite small. The examples I've seen are specifying the window size as follows... new SXSSFWorkbook(100) Whereas the example we've just been through for checking the password isn't actually using the Workbook. Is it possible to combine to two processes or to achieve the password check using only the Workbook? Also, is there a similar idea of sliding window available for the older XLS files so as to reduce the memory footprint? Thanks for all your help. Tom -----Original Message----- From: Nick Burch [mailto:[email protected]] Sent: 02 September 2011 12:22 To: POI Users List Subject: Re: How to check whether an XLSX has a read password On Fri, 2 Sep 2011, Simmons, Tom (GE Oil & Gas, VG) wrote: > What I think I have gleaned so far is I should open the file... > > POIFSFileSystem pfs = new POIFSFileSystem(new File("d:\\file.xlsx")); Things are a bit tricky for you. POIFSFileSystem is only used for OLE2 based documents. That normally means .xls, .doc and .ppt (amongst others) If you want to open a regular OOXML file (such as a .xlsx or a .pptx) you need to use OPCPackage (or just the appropriate usermodel class like XSSFWorkbook) However, encrypted OOXML files are special. They're actually stored as a OLE2 file containing the encrypted xml contents So, if you have a .xlsx file, and you want to know if it's encrypted or not, you could do: boolean isEncrypted = false; try { new POIFSFileSystem(new FileInputStream("question.xlsx")); isEncrypted = true; } catch(OfficeXmlFileException e) { // This is a regular ooxml .xlsx file } Nick --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
