File encryption and decryption are very common operations in any business organization. In many scenarios, you do not want unauthorized access to your files. In fact, Excel files are mostly used to save important data due to their security and rich data representation features. However, you can make your Excel files password protected. In this blog post, you will learn how to decrypt or encrypt Excel Files in Java using this Java Excel library. By the end of this blog post, you will be able to set password security on your Excel files programmatically.
The following topics shall be covered in this article:
Java Excel library installation
The installation process is quite easy and straight. In addition, you may visit the installation guide in case of any issue.
However, you can quickly install by either downloading the JAR files or following the Maven configurations mentioned below:
<repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>https://repository.aspose.com/repo/</url> </repository> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-cells</artifactId> <version>22.6</version> </dependency>
Encrypt Excel Files in Java
Once the installation is successful, we can write the code snippet to encrypt Excel file programmatically in a Java application.
You may follow the steps mentioned below:
- Instantiate a Workbook object and load an Excel file path.
- Password protect the file by calling the setPassword method.
- Specify XOR encrption type by setting values of the setEncryptionOptions method.
- Specify strong Encryption type (RC4,Microsoft Strong Cryptographic Provider).
- Invoke the save method to save the Excel file.
You can see the output in the image below:
Decrypt Excel Files programmatically
You can decrypt the Excel files using this Java Excel Library. Moreover, you can automate the whole process by writing a few lines of source code in Java.
Please follow the following steps and the code snippet:
- Create an object of LoadOptions class that represents the options of loading the file.
- Invoke the loadOptions.setPassword method to set the password of the workbook.
- Instantiate an instance of the Workbook class and load the XLSX file with options.
- setPassword method will remove the password by setting the password value null.
- Save the file by calling the save method.
Get a Free License
You may get a free temporary license to try the API beyond evaluation limitations.
In this blog post, you have learned how to decrypt or encrypt Excel Files in Java programmatically. You can automate the file encryption and decryption processes by installing this Java Excel library. Moreover, you can visit the documentation to know other features. Finally, stay connected with conholdate.com for regular updates.
Ask a question
You can let us know about your questions or queries on our forum.
How do I password protect an Excel File in Java?
You may install this Java Excel API to set a password on your business Excel files programmatically.
How do I Encrypt an xlsx File?
How do you decrypt a file in Java?