Encrypt Decrypt Excel Files Node.js

MS Excel is a powerful tool that allows you to perform various spreadsheet manipulation operations. You can organize data, apply computations, generate charts, define your custom logic using VBA modules, and so on. An important feature that MS Excel provides is encryption and decryption of the Excel files. In accordance with that, this article covers how to encrypt/decrypt and password-protect Excel files in Node.js applications.

Node.js API to Encrypt and Decrypt Excel Files

For encryption and decryption of Excel files, we will use Aspose.Cells for Node.js via Java. It is a feature-rich API that allows you to encrypt and decrypt the workbooks within a few lines of code. In addition, you can password-protect an Excel file seamlessly. You can either download the API or install it using the following npm command.

> npm install aspose.cells

Encrypt Excel XLSX or XLS Files in Node.js

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

  • XOR
  • COMPATIBLE (Office 97/2000 compatible)
  • ENHANCED CRYPTOGRAPHIC PROVIDER V1
  • STRONG CRYPTOGRAPHIC PROVIDER

Whereas, SHA and AES encryption techniques are used for 2007/2010 workbooks. The following are the steps to encrypt an Excel file in Node.js.

The following code sample shows how to encrypt an Excel XLSX file in Node.js.

Decrypt an Excel File in Node.js

To decrypt an encrypted Excel file, you will need to specify its password. The following are the steps to decrypt an Excel file in Node.js.

The following code sample shows how to decrypt a password-protected Excel file in Node.js.

Get a Free API License

In case you want to try the API without evaluation limitations, you can get a free temporary license.

Conclusion

In this article, you have learned how to encrypt or decrypt Excel files in Node.js applications. You can simply integrate the provided code into your Node.js applications to encrypt/decrypt XLSX/XLS files. In case you want to explore more about the Node.js spreadsheet manipulation API, visit the documentation. Also, you can ask your questions via our forum.

See Also