How to Clear a Row from an Excel Spreadsheet using Node.js
Looking for an easy way to remove specific rows of data from a spreadsheet with code? You’re in luck: a low-code API can do the trick.
With the code examples provided below in this article, you can easily take advantage of a free API that allows you to target and remove content from a specific row in your Excel spreadsheets. You can structure your request like the JSON example below:
{
"InputFileBytes": "string",
"InputFileUrl": "string",
"WorksheetToEdit": {
"Path": "string",
"WorksheetName": "string"
},
"RowIndex": 0
}
And once the operation is complete, you’ll receive your completed edits in the form of a temporary editing URL which can be used to either chain additional Excel API edits together (see other Cloudmersive Excel editing APIs) or download your finalized document result.
{
"Successful": true,
"EditedDocumentURL": "string"
}
Downloading your finalized document result can be accomplished using a secondary API call, and both API calls can be authorized with a single free-tier Cloudmersive API key (these allow a limit of 800 API calls per month).
To structure your API call, you can begin by installing the SDK. Either run this command:
npm install cloudmersive-convert-api-client --save
Or add this snippet to your package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
With that out of the way, you can copy the ready-to-run code examples into your file to call the API that clears your targeted Excel row:
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.ClearXlsxRowRequest(); // ClearXlsxRowRequest | Document input request
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editDocumentXlsxClearRow(input, callback);
And you can use the below code to call the API that downloads your finalized document encoding from the temporary editing URL:
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 reqConfig = new CloudmersiveConvertApiClient.FinishEditingRequest(); // FinishEditingRequest | Cloudmersive Document URL to complete editing on
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editDocumentFinishEditing(reqConfig, callback);
That’s all the code you’ll need. Easy!