poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nick Burch <nick.bu...@alfresco.com>
Subject Re: How to check whether an XLSX has a read password
Date Fri, 02 Sep 2011 11:22:03 GMT
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 

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


To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org

View raw message