How to get the cell value from an Excel XLSX spreadsheet or worksheet in C# .NET Framework
Extracting specific cell data from a worksheet opens up a plethora of practical possibilities. This functionality can be quite tricky to set up, though. That’s where a handy API comes in — our shortcut to productivity!
In order to get started, we need to install our API client using NuGet. Simply enter the following code snippet into the console in Package Manager:
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0
Now call EditDocumentXlsxGetCellByIndex and provide the index for the cell we want.
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 EditDocumentXlsxGetCellByIndexExample{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 GetXlsxCellRequest(); // GetXlsxCellRequest | Document input requesttry{// Get cell from an Excel XLSX spreadsheet, worksheet by indexGetXlsxCellResponse result = apiInstance.EditDocumentXlsxGetCellByIndex(input);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditDocumentApi.EditDocumentXlsxGetCellByIndex: " + e.Message );}}}}
Done. Our response will be given in this format:
{
"Successful": true,
"Cell": {
"Path": "string",
"TextValue": "string",
"CellIdentifier": "string",
"StyleIndex": 0,
"Formula": "string"
}
}
How easy was that? If you would like other, similar functions, be sure to check out our documentation for more useful stuff, including format conversion and document editing.