encrypt decrypt excel files in java

MS Excel provides you with a wide range of features to keep and analyze the data seamlessly. You can perform computations, generate charts as well as define your custom logic using VBA modules. Knowing the importance of the data in spreadsheets, MS Excel allows you to protect the workbooks using encryption. Furthermore, you can password protect the Excel files to avoid unauthorized access. In accordance with that, this article covers how to encrypt or decrypt Excel files using Java.

Java API to Encrypt and Decrypt Excel Files

Aspose.Cells for Java is a powerful spreadsheet manipulation API that lets you create and manipulate Excel files seamlessly. Furthermore, it allows you to encrypt and decrypt the workbooks within a few lines of code. In addition, you can protect an Excel file with a password. Aspose.Cells for Java can either be downloaded as JAR or installed using the following Maven configurations.

<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>20.12</version>
</dependency>

Encrypt Excel Files using Java

Aspose.Cells for Java provides the following encryption types for Excel 2003 files.

However, 2007/2010 workbooks are encrypted using SHA and AES encryption techniques in the same way MS Excel does. The following are the steps to encrypt an Excel file using Aspose.Cells for Java.

For demonstration, the following code sample shows how to encrypt an Excel file using Java.

Decrypt Excel Files using Java

In order to decrypt an encrypted Excel file, you only need to provide its password and the rest will be handled by Aspose.Cells for Java. The following are the steps to decrypt an Excel file using Java.

The following code sample shows how to decrypt a password-protected Excel file using Java.

Verify Password of an Encrypted Excel File

In addition to encryption/decryption, Aspose.Cells for Java also allows you to verify the password of a protected Excel file. The following are the steps to perform password verification.

The following code sample shows how to verify the password of an encrypted Excel file using Java.

Encrypt Excel Files Online

Encrypt your Excel files using our free spreadsheet encryption tool. It is a web-based tool that can be accessed from your browser without creating any account.

Get a Free API License

Get a free temporary license and encrypt your Excel files without any evaluation limitations.

Conclusion

In this article, you have learned how to encrypt or decrypt Excel files using Java. Furthermore, you have seen how to verify the password of an encrypted Excel file. In addition, we have provided you with a free online tool to encrypt Excel files.

In case you want to explore more about the Java spreadsheet manipulation API, visit the documentation.

See Also