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]

Reply via email to