How to get worksheets from an Excel XLSX spreadsheet in Node.JS

Extracting worksheets from XLSX files is a useful feature, but a difficult one to implement through standard means. With just a few lines of code, I will be showing you a method that is significantly simpler, trivial in fact. Let’s get started;

With this reference in package.json, you will be able to access the API client that we will be using.

"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"

With a few lines of code (which I have laid out below) you can instance the Edit Document API, which will allow you to call editDocumentXlsxGetWorksheets.

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.EditDocumentApi();var input = new CloudmersiveConvertApiClient.GetXlsxWorksheetsRequest(); // GetXlsxWorksheetsRequest | Document input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editDocumentXlsxGetWorksheets(input, callback);

Input your document as part of the request object GetXlsxWorksheetsRequest and you will have your worksheets in a few heartbeats.

Image for post
Image for post

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store