How to Convert Excel XLSX to Important Data Formats in Nodejs

Cloudmersive
3 min readMay 10, 2024

While Excel XLSX makes it easy to customize and “beautify” data sets, it’s not the best format for sharing data at scale.

Before sharing important Excel data at scale, we’ll want to convert our spreadsheets to other formats like JSON, XML or CSV first.

Thankfully, it’s easy to make conversions from Excel XLSX to these other common formats with a few low-code APIs.

We can call each API using the ready-to-run Nodejs code examples provided below, we can authorize each API call with the same free Cloudmersive API key (these allow a limit of 800 total API calls per month with no commitments).

Our first order of business is to install the client SDK. We can install using NPM install:

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

Or we can add the Node client to our package.json:

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

After that, we can call our various Excel conversion functions. We can convert Excel to JSON using the following code examples:

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

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


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

And we can convert Excel to XML using the below code examples:

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

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


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

Finally, we can convert an Excel file with only one worksheet to CSV using the below code:

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.convertDocumentXlsxToCsv(inputFile, opts, callback);

And we can convert an Excel file with multiple worksheets to CSV using the below code:

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);

That’s all there is to it — now we have a few easy-to-use Excel conversion APIs at our disposal.

--

--

Cloudmersive

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