How to Get Images from an XLSX Spreadsheet using Node.js

Cloudmersive
2 min readNov 15, 2023

--

We can access image objects within an XLSX file easily with the right library or API.

Using the code provided further down the page, we can take advantage of an API solution to grab images from our XLSX files and return them — along with their specific file path, embed ID, content type, file name & file contents URL — in an array of objects, as depicted in the JSON example below:

{
"Successful": true,
"Images": [
{
"Path": "string",
"ImageDataEmbedId": "string",
"ImageDataContentType": "string",
"ImageInternalFileName": "string",
"ImageContentsURL": "string"
}
]
}

To make our request, we’ll just need to submit an object containing our file bytes/file URL and specific references to the worksheet we’re pulling from:

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

We can now begin structuring our API call by first installing the SDK. Let’s 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"
}

Lastly, let’s call the function using the below code. We can authorize our API requests within this code using a free-tier API key (these will allow up to 800 API calls per month with no additional commitment):

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.GetXlsxImagesRequest(); // GetXlsxImagesRequest | Document input request


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

That’s all there is to it — our request will return the image objects in our worksheets and we can subsequently use those files elsewhere. Easy!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet