-1

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.

Community
  • 1
  • 1
Dmitry Kokora
  • 777
  • 1
  • 7
  • 14

1 Answers1

1

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);
    }
Chandana
  • 2,578
  • 8
  • 38
  • 55