How to set and update cell contents in an Excel XLSX by index in Node.JS
Today’s goal holds no mystery, we are simply changing cell values in Node.JS. The key factor to consider here is how much time you want to spend on this endeavor. If you want this over with quickly, then let me show you how to pull this tooth in under 5 minutes.
We start by adding the following dependency reference to our package.json. This will import our API client, which we will be using as our shortcut.
"dependencies": {
"cloudmersive-convert-api-client": "^2.1.6"
}
Now if we instantiate our API, we can then use that instance to call editDocumentXlsxSetCellByIndex. Here’s a mock-up of what that should look like:
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.SetXlsxCellRequest(); // SetXlsxCellRequest | Document input requestvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.editDocumentXlsxSetCellByIndex(input, callback);
There you have it! You can now change cell values using their indexes until the cows come home. If you look at the rest of this library, there are all sorts of good functions like this. They automate such tasks as creating new Excel files based on existing row and column data, and converting documents between different formats.