javaxlsxlsxjxljexcelapi

Password protected xls/xlsx file in java


I have created password protected zip file which has xls file with the help of this http://java.sys-con.com/node/1258827.

My question is ,Is there any java api which will create password protected xls file instead of zip file. I want to directly apply password on xls file.Encryption/Decryption is the option but want to prompt when when double clicked on file.

edit: I got this
HSSFSheet.protectSheet("xyz");but it only makes sheet read only.

Even I have tried this hssfworkbook.writeProtectWorkbook("abc", "abc");but its not prompting for password.

Edit1:There is the method in org.apache.poi.hssf.record.crypto.Biff8EncryptionKey package to open password protected excel file org.apache.poi.hssf.record.crypto.Biff8EncryptionKey.setCurrentUserPassword(password); Is there any method to set password on unprotected excel file?

Edit2: I tried JExcel API

Workbook w=Workbook.getWorkbook(new File("c:\\employees22533.xls"));
Sheet ws=null;
ws=w.getSheet("Employee List");
SheetSettings sh=ws.getSettings();
sh.setPassword("abc");

But its not setting any password


Solution

  • I've personally used JExcelApi but I do not remember having seen something about password protection into it. As far as JExcelApi is concerned there are a number of features where the answer is known to be "No":

    I personally think that if Password Protection would've been possible(with open source api's) Their would be a lot of tutorials available on internet and you could search them simply by a quick Google search, Unfortunately none of the freely available Java spreadsheet APIs seems to support writing encrypted spreadsheets.

    However If you're willing to use commercial api/library then see this