Split an XLSX File into Separate Worksheets using Node.JS

Cloudmersive
2 min readDec 14, 2020

--

Excel spreadsheets are very useful for organizing and sharing complex data sets in easy-to-understand formatting. However, for the creator of an XLSX file, each worksheet within the file may represent and fill different needs, and thus may need to be shared separately. The following API will split an XLSX file into separate worksheets in new files.

To use this API, run this command to install the SDK:

npm install cloudmersive-convert-api-client --save

You can also add this snippet to your package.json:

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

Then, call the function:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveConvertApiClient.SplitDocumentApi();var inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // 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);

This will return one new file for each separated worksheet (i.e., if your original file had five worksheets, the output will be five new files). You can retrieve the API Key from Cloudmersive at no cost and with no commitment. This will give you access to 800 monthly calls across our library of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet