How to set and update cell contents in an Excel XLSX by index in C# .NET Framework

Cloudmersive
2 min readFeb 7, 2020

--

Editing Excel files is a pretty common task for a variety of apps and sites, so isn’t it about time someone came up with an easy way to do it? Well, we did, and it comes in the form of a handy dandy API.

To kick things off, let’s install Cloudmersive’s API client via the Package Manager console:

Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0

With that done, we can move on to calling EditDocumentXlsxSetCellByIndex, as you see demonstrated here.

using System;using System.Diagnostics;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;namespace Example{public class EditDocumentXlsxSetCellByIndexExample{public void main(){// Configure API key authorization: ApikeyConfiguration.Default.AddApiKey("Apikey", "YOUR_API_KEY");// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// Configuration.Default.AddApiKeyPrefix("Apikey", "Bearer");var apiInstance = new EditDocumentApi();var input = new SetXlsxCellRequest(); // SetXlsxCellRequest | Document input requesttry{// Set, update cell contents in an Excel XLSX spreadsheet, worksheet by indexSetXlsxCellResponse result = apiInstance.EditDocumentXlsxSetCellByIndex(input);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditDocumentApi.EditDocumentXlsxSetCellByIndex: " + e.Message );}}}}

We can then supply this with our input using the following format:

{
"InputFileBytes": "string",
"InputFileUrl": "string",
"WorksheetToUpdate": {
"Path": "string",
"WorksheetName": "string"
},
"RowIndex": 0,
"CellIndex": 0,
"CellValue": {
"Path": "string",
"TextValue": "string",
"CellIdentifier": "string",
"StyleIndex": 0,
"Formula": "string"
}
}

And that’s all there is to it. Our cell’s value is now updated.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet