Last active
August 10, 2022 07:59
-
-
Save conholdate-gists/cb66543c79c30623969adfb102cd8cdf to your computer and use it in GitHub Desktop.
Encrypt Excel Files in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create an object of LoadOptions class that represents the options of loading the file. | |
LoadOptions loadOptions = new LoadOptions(); | |
// Invoke the setPassword method to set the password of the workbook. | |
loadOptions.setPassword("1234"); | |
// Instantiate an instance of the Workbook class and load the xlsx file with options | |
Workbook workbook = new Workbook("sample.xlsx", loadOptions); | |
// Remove the password by setting the password value null. | |
workbook.getSettings().setPassword(null); | |
// Save the file by calling the save method. | |
workbook.save("Book1.xlsx"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate a Workbook object and load an Excel file path | |
Workbook workbook = new Workbook("sample.xlsx"); | |
// Password protect the file by calling the setPassword method. | |
workbook.getSettings().setPassword("1234"); | |
// Specify XOR encrption type by setting values of the setEncryptionOptions method. | |
workbook.setEncryptionOptions(EncryptionType.XOR, 40); | |
// Specify Strong Encryption type (RC4,Microsoft Strong Cryptographic Provider). | |
workbook.setEncryptionOptions(EncryptionType.STRONG_CRYPTOGRAPHIC_PROVIDER, 128); | |
// Invoke the save to save the Excel file. | |
workbook.save( "EncryptingFiles_out.xls"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment