How to split an Excel XLSX into Separate Worksheets in Node.JS

Today we are splitting XLSX files into separated worksheets.

With the following dependency reference added to our package.json file, our client installation will be taken care of.

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

A function call for splitDocumentXlsx comes next.

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.SplitDocumentApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var opts = {'returnDocumentContents': true // Boolean | Set to true to return the contents of each Worksheet directly, set to false to only return URLs to each resulting worksheet.  Default is true.};var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.splitDocumentXlsx(inputFile, opts, callback);

Now we can specify if we want to be given the worksheet content directly or have the worksheets available for download via URLs instead. After that, input your XLSX file and you are done!

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