How to create a new Excel XLSX spreadsheet from column and row data in Node.JS

Creating new Excel files from within Node.JS is actually a lot more of a hassle than it really should be. That’s why I’m going to lay out the easy method for you.

For this approach, we are going to use an API. That means we shall begin by installing our client, like this:

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

With the following lines of code, we can instance our API, then call editDocumentXlsxCreateSpreadsheetFromData:

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.CreateSpreadsheetFromDataRequest(); // CreateSpreadsheetFromDataRequest | Document input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editDocumentXlsxCreateSpreadsheetFromData(input, callback);

And just like that, we have created our new Excel spreadsheet from our row and column data. If you do not have this data available and just want to create a blank XLSX, you can use editDocumentXlsxCreateBlankSpreadsheet instead. In this library, there are other functions that allow you to update specific cells, add worksheets, and more. When complete, your file can be finalized and downloaded with editDocumentFinishEditing.

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