How to password protect a zipped Excel file in Java?

后端 未结 3 504
说谎
说谎 2021-01-06 00:27

I have a question about password protecting an Excel file.

The situation is that, I have a zip file, that has an Excel file in it. I need to write a Java program, to

相关标签:
3条回答
  • 2021-01-06 00:55
    • Use java.util.zip or zip4j to decompress file to some temp direcotry or to memory, if you know it's small.
    • Then use HSSFWorkbook.writeProtectWorkbook from Apache POI library
    • Compress Excel workbook again.
    0 讨论(0)
  • 2021-01-06 00:58

    Without uncompressing, Its impossible to password protect excel which is inside a zip file.

    Here is what you can do

    • Unzip the content using tips in What is the best way to extract a zip file using java and Compressing and Decompressing Data Using Java APIs
    • Password protect extracted excel file using tips in Password Protected Excel File
    • Zip the password protected excel file using tips in Java Compress Large File
    0 讨论(0)
  • 2021-01-06 01:18

    I think you should check out truezip (Truezip website). It provides read/write access to ZIP, JAR, EAR, WAR etc and supports appending to existing ZIP files.

    I suggest you create your zip file without the excel file in it, create your passworded excel file as directed in the link you provided and then use truezip to write this excel file to the archive. Hope this helps

    0 讨论(0)
提交回复
热议问题