File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes how to check if a docx, xlsx, or pptx file is password protected using apache POI? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "how to check if a docx, xlsx, or pptx file is password protected using apache POI? " Watch "how to check if a docx, xlsx, or pptx file is password protected using apache POI? " New topic
Author

how to check if a docx, xlsx, or pptx file is password protected using apache POI?

Thileepa Asokan
Greenhorn

Joined: Jun 08, 2011
Posts: 6
My requirement is to just check if the MS Office 2007 document(docx,xlsx or pptx) is password protected or not. I plan to use apache POI for that.

For doc, xls and ppt documents, I am just trying to create an instance of HWPFDocument, HSSFWorkbook or HSLFSlideShow and checking for the EncryptedDocumentException thrown.

Sample code:


When I try a similar thing for docx, xlsx or pptx document, org.apache.poi.POIXMLException( org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]") is thrown. I believe that this exception is thrown not only when the file is password protected but also when the file is invalid or corrupt. My guess is that the exception is thrown when trying to access the [Content_Types].xml after unzipping the file(package).

Now. my question again: Is there a more elegant way (other than checking for the org.apache.poi.POIXMLException) to validate if a docx, xlsx or pptx document is password protected?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Hi and welcome to the JavaRanch.

Please tell us when you're post the same message to other websites. We allow it be you have to be forthright about it.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Thileepa Asokan
Greenhorn

Joined: Jun 08, 2011
Posts: 6
Hi Wouter,

I posted it in another forum but the status has been showing as pending for more than a day( and is still in the same status) and so, I have registered in Java Ranch and posted my question here.

Hope I will get my question answered.

Thanks.

Thileepa Asokan
Greenhorn

Joined: Jun 08, 2011
Posts: 6
And I will certainly declare it in the forum if I got my question answered.

Thanks again.
Tom Simmons
Greenhorn

Joined: Nov 16, 2010
Posts: 11
Did you ever get an answer on this, I need to do exactly the same thing - namely check files that people are uploading to make sure they aren't passworded.


Tom
Thileepa Asokan
Greenhorn

Joined: Jun 08, 2011
Posts: 6
Nope. No answer as of now..
Tom Simmons
Greenhorn

Joined: Nov 16, 2010
Posts: 11
Have a look at this thread I started on the poi mailing list, seems to be going somewhere and I'm getting good results.

http://thread.gmane.org/gmane.comp.jakarta.poi.user/17344

Tom
Tom Simmons
Greenhorn

Joined: Nov 16, 2010
Posts: 11
Tom Simmons wrote:Have a look at this thread I started on the poi mailing list, seems to be going somewhere and I'm getting good results.

http://thread.gmane.org/gmane.comp.jakarta.poi.user/17344

Tom


Thileepa,

I don't know if you have been keeping an eye on the above thread, however I have now successully been able to check XLS and XLSX files for passwords, including being able to handle large files within 1-2 seconds with tiny memory footprints.

Next stop is DOC and DOCX files.


Tom
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to check if a docx, xlsx, or pptx file is password protected using apache POI?