I am developing a simple Java program to create an Excel file using (Apache POI) API.
I am using Oracle 10g as a database and using the ojdbc14 JAR file.
I have a table called USERINFO, having three columns, namely USERNAME, PASSWORD, and NAME.
Now using Apache POI, I have been able to put all the rows in an Excel file.
Since the file contains sensitive data such as username and password, I want to make it password protected.
On forums, I have found how to read password protected files, but not how to create them.
So how I can achieve this?
Updated: As of version 3.10 POI supports encryption as well as decryption for XLSX files. See the "Encryption Support" page on POI’s website. The below is still relevant for XLS binary workbooks.
If you’re willing to pay for commercial software, the latest version of ExtenXLS has full read and write support for all the encryption formats supported by Excel. Just construct an
EncryptedWorkBookHandleinstead of the normalWorkBookHandle. That will use the strongest possible cipher supported by an unmodified JRE, RC4 for XLS and 128-bit AES for XLSX. If you want to use 256-bit AES with OOXML and you’ve installed the JCE unlimited policy you can do so with theMSOfficeEncrypterclass.JExcelAPI, a popular open-source Java spreadsheet API, does not appear to support encryption at all. Aspose.Cells, a commercial offering, supports stong encryption. The documentation for Actuate’s e.Spreadsheet seems to have disappeared from the ‘net, so I can’t tell whether it supports encryption or not.
Since none of the freely available Java spreadsheet APIs seems to support writing encrypted spreadsheets, if you’re not willing to use commercial software you’ll need to come up with a workaround. You could, for example, write the spreadsheet into an encrypted ZIP file.
java.util.zipdoesn’t support encryption, but it looks like Zip4j does.Full disclosure: I work for Extentech, the company behind ExtenXLS.