How to Get the Columns from an Excel XLSX Spreadsheet using Node.js

Cloudmersive
2 min readNov 15, 2023

--

Retrieving objects from within an Excel file is easier than we might think — especially with the help of a free API.

Using the below code, we can take advantage of a free API to easily extract the columns from an XLSX file and return those columns as separate objects. Our response will look like the following JSON example:


"Successful": true,
"Columns": [
{
"Path": "string",
"HeadingCell": {
"Path": "string",
"TextValue": "string",
"CellIdentifier": "string",
"StyleIndex": 0,
"Formula": "string"
}
}
]
}

We can authorize our API call with a free-tier API key, and we can get one of those by registering a free account on the Cloudmersive website (these allow a limit of 800 API calls per month with no additional commitment).

To begin structuring our request, let’s first install the SDK. We can either run this command:

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

Or we can add the following snippet to our package.json:

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

Following that, we can 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.GetXlsxColumnsRequest(); // GetXlsxColumnsRequest | Document input request


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

We can structure our request object like the following JSON example:

{
"InputFileBytes": "string",
"InputFileUrl": "string",
"WorksheetToQuery": {
"Path": "string",
"WorksheetName": "string"
}
}

That’s all there is to it — now we can easily retrieve column objects directly from our XLSX spreadsheets with minimal code!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet