How to Convert Multi-Worksheet XLSX File to CSV using Node.js

Cloudmersive
2 min readNov 16, 2023

--

Looking for an easy way to break down each worksheet of an Excel document into its own CSV file?

Using the below code, we can easily take advantage of a free API that converts XLSX documents with multiple worksheets into one CSV document per worksheet. Our request will return one response object per worksheet with our CSV contents displayed along with the original worksheet names.

We’ll just need a free-tier API key to authorize our requests — this will allow a limit of 800 API calls per month with no commitment.

We can begin structuring our API call by installing the SDK. We can either run this command:

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

Or add this snippet to our package.json:

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

Finally, we can call the function using the below code to make our request:

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.ConvertDocumentApi();

var inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Input file to perform the operation on.

var opts = {
'outputEncoding': "outputEncoding_example" // String | Optional, set the output text encoding for the result; possible values are UTF-8, ASCII and UTF-32. Default is UTF-8.
};

var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.convertDocumentXlsxToCsvMulti(inputFile, opts, callback);

It’s worth noting we can also set the output text encoding for the resulting CSV documents (default is UTF-8). Our other options are ASCII and UTF-32.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet