How to Get the Styles from an Excel XLSX Spreadsheet or Worksheet using Node.js
Creating a uniform standard for our spreadsheets starts with synchronizing style data. With the help of a free API, we can easily retrieve that information programmatically with zero manual intervention.
Using the below code, we can take advantage of a free API that gets the cell styles from an XLSX document and returns that information in a simple object. Each “cell styles” object will contain a path, name, format ID and built-in ID value.
With a free-tier API key, we can make up to 800 API calls in our application per month with no additional commitments. Once we have our API key copied to our clipboard, we can easily paste it within the code examples below to finalize our request.
To begin structuring our API call, we can begin by installing the SDK. We can either run the following command:
npm install cloudmersive-convert-api-client --save
Or we can add this snippet to our package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
With installation out of the way, we can use the below code to 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.EditDocumentApi();
var input = new CloudmersiveConvertApiClient.GetXlsxStylesRequest(); // GetXlsxStylesRequest | Document input request
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editDocumentXlsxGetStyles(input, callback);
And we can follow the below JSON example when we structure our input request:
{
"InputFileBytes": "string",
"InputFileUrl": "string"
}
That’s all there is to it — no more code required!