0

As background, I am using com.jexcel.util.ExcelAdapter to password protect my excel file that was generated via jasperreports. This is currently working just fine when executed in windows but is now causing an error when I executed my java code in linux server.

It says :

java.io.IOException: Cannot run program "cmd": java.io.IOException: error=2, No such file or directory 
  at java.lang.ProcessBuilder.start(Unknown Source)
  at java.lang.Runtime.exec(Unknown Source)
  at java.lang.Runtime.exec(Unknown Source)
  at java.lang.Runtime.exec(Unknown Source)
  at com.jexcel.util.ExcelAdapter.setPasswordXlsFile(ExcelAdapter.java:65)

Please, do help. I am executing my code via the linux konsole using java -jar PassProtect.jar

I found these links :

Password protected xls/xlsx file in java

Create a password protected excel file using apache poi?

Both were saying that neither Apache POI nor JExcel Api have the functionality to pass-protect an existing excel file (all they can do is to write-protect the excel sheets). I already knew that sad fact. :(

com.jexcel.util.ExcelAdapter actually did the trick for me, it really does can pass-protect an entire workbook (so try using this if you don't have the need to execute your codes on a linux server for this is only working on windows). That's the problem, I need to execute my code in linux and as was discussed above, ExcelUtil cannot do that for me. Do you know anything that's like ExcelUtil but will work on linux instead?

I can't use commercial softwares like Aspose. I can't also save the file on a password-protected zip file instead because I need to transfer the excel file into an ftp server and also I need to send it via email, which is impossible if I would store it on zip file (or was it? I can't send or transfer the zip file itself 'coz recipients would be expecting the .xls file).

Please help me. Is there any way or any API or any sample code that could password protect a file that linux would accept? I am running out of ideas (and search results are all saying the same thing) as of the moment.

Community
  • 1
  • 1
kazeopeia
  • 15
  • 1
  • 7

1 Answers1

0

Not sure, but from the exception it looks as if the adapter is trying to execute the windows command shell "cmd.exe", which is unlikely to work under any OS not being windows... Maybe you should try a different approach, if your application needs to run under linux. There are Java libraries to work with office documents available as part of the Apache project. Have a look at http://poi.apache.org/

Dirk
  • 30,623
  • 8
  • 82
  • 102
  • Thanks. My original goal is to generate a password protected excel file (i.e. the entire workbook not just the worksheet). I've tried Poi and Jxl Api but no use because they can only write protect the worksheet. :( – kazeopeia Dec 02 '12 at 02:40