Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Possible Duplicate:
How can I access password protected Excel workbook in Java using POI api

How to open a password protected Word/Excel-file using Apache POI in Java ? Please, write the code.

share|improve this question

marked as duplicate by jahroy, Luiggi Mendoza, Augusto, Matti Lyra, guido Nov 10 '12 at 10:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

Apache POI support for reading encrypted XLSX and DOCX files. Refer the Apache POI documentation

Your code should be something like this:

 EncryptionInfo info = new EncryptionInfo(filesystem);
    Decryptor d = Decryptor.getInstance(info);

    try {
        if (!d.verifyPassword(password)) {
            throw new RuntimeException("Unable to process: document is encrypted");
        }

        InputStream dataStream = d.getDataStream(filesystem);
        HSSFWorkbook wb = new HSSFWorkbook(dataStream);
        // parse dataStream

    } catch (GeneralSecurityException ex) {
        throw new RuntimeException("Unable to process encrypted document", ex);
    }
share|improve this answer
filesystem ? POIFSFileSystem filesystem = new POIFSFileSystem(new FileInputStream("example.xls")); – user1808293 Nov 11 '12 at 0:00
Yes, filesystem mean POIFSFileSystem. poi.apache.org/apidocs/org/apache/poi/poifs/filesystem/… – Chandana Nov 11 '12 at 0:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.