How to remove a worksheet from an Excel XLSX spreadsheet in Node.JS

The process of removing a worksheet from an XLSX file is about to go from being an afternoon of poignant suffering to an absolute breeze!

Adding this reference to our package.json will let us bring in our client.

"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}

Now we are going to call the function editDocumentXlsxDeleteWorksheet using a newly instance of the Edit Document API. Here’s an example of how this works:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.EditDocumentApi();var reqConfig = new CloudmersiveConvertApiClient.RemoveXlsxWorksheetRequest(); // RemoveXlsxWorksheetRequest | Spreadsheet input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editDocumentXlsxDeleteWorksheet(reqConfig, callback);

As you can see, we will need to put our input file and worksheet index into our request object, RemoveXlsxWorksheetRequest. To enumerate these worksheets, you can use the other API function editDocumentXlsxGetWorksheets. And that’s really all that you need to know, the rest is gravy!

Image for post
Image for post

Written by

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store