Password-Protect Excel using Password Protection Service

Working with MS Excel files to store, represent, and share business data is a routine task. Excel Workbooks may also contain confidential information and it might become a security risk when sharing outside the organization. Fortunately, there is a feature to lock Excel spreadsheets with a password so that no third party can open files and access the data. However, we can automate the whole process programmatically using a password protection service. This GroupDocs.Merger Cloud SDK for Node.js provides features to password-protect Excel files efficiently.

The following points will be covered in this blog post:

Installation of Password Protection Service

The installation process of this password protection service is very simple. Since we will set up this API in our Node.js-based project and GroupDocs.Merger Cloud SDK for Node.js is available in the NPM package registry.

So, you may run the following command to install this Node.js SDK to achieve the file lock feature:

npm install groupdocs-merger-cloud

How to Obtain API Credentials to Use GroupDocs.Merger Cloud SDK?

Once installation is successful, the next step is to obtain the Client ID and Client Secret by following the steps mentioned below:

  • Navigate to the dashboard and log in.
  • Create a new application and storage.
  • Hit the “Save” button and you can get your API credentials by navigating into your newly created app.

The whole process is shown below:

obtain API credentials of password protection service

Password-Protect Excel Files Programmatically in Node.js?

We are all set to implement the functionality to add password to Excel file using GroupDocs.Merger Cloud SDK for Node.js. In addition, we will not only write steps to password-protect spreadsheets but we will also write the code snippet that will add password to Excel workbooks seamlessly.

The following are the steps to use this password protection service:

  • Include the groupdocs-merger-cloud module in your app.
  • Initialize Configuration object using Client ID and Client Secret.
  • Initialize an instance of the FileApi class with a configuration object.
  • Open the file in IOStream from the disc.
  • Invoke the fs.readFile method to read the file.
  • Initialize an object of the UploadFileRequest class to make a file upload request.
  • Upload file the file by calling the uploadFile method.
  • Instantiate the SecurityApi with the API credentials.
  • Prepare an object of the Options class by setting the values such as filePath, password, outputPath, etc.
  • Invoke the addPassword method to password-protect Excel file that will save the resultant file on the cloud.
  • Create a request to download the resultant file by initializing an object of the DownloadFileRequest class.
  • Download the file by calling the downloadFile method.

Copy & paste the following code into your main file and run the project to lock Excel spreadsheet programmatically:

You may use your source Excel file that you want to make password-protected.

After a successful run, you will see a file sample-protected.xlsx downloaded on your machine. Once you open this file, you will see the output shown in the image below:

add password to Excel

Add Password to Excel Files Online

You may use our online tool to lock Excel spreadsheets instantly. Moreover, it is free and you can use it without any subscription or account creation.

password protect Excel online

Conclusion

This brings us to the end of this blog post. We have learned how to password-protect Excel files using GroupDocs.Merger Cloud SDK for Node.js. In addition, we also have gone through the installation and setup processes of this password protection service. This guide will help you if you are looking to automate the process of locking Excel spreadsheets programmatically. Moreover, you can interact with our API directly in the browser and you can find the source code of Node.js SDK on GitHub.

Further, we recommend you follow our Getting Started guide.

Finally, groupdocs.cloud is consistently writing new articles. So, please stay tuned for the latest updates.

Ask a question

You can let us know about your questions or queries on our forum.

Frequently Asked Questions – FAQs

How can I protect Excel file with password?

You can automate the process of adding a password to Excel workbooks using GroupDocs.Merger Cloud SDK for Node.js. In addition, please follow this link to know the answer in detail.

How to password protected Excel file using Python?

GroupDocs.Merger Cloud SDK for Python lets you password-protect Excel files programmatically. Please visit documentation for further details.

See Also