How to get rows and cells from an Excel XLSX spreadsheet in C# .NET Framework
So you need a quick way to extract row and cell info from an Excel file? Well, we’ve got you covered.
We shall start simply enough by installing our API client. This is accomplished by running this command in the console of Package Manager.
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 2.2.0
So far, so good. Next we are going to implement the function we need from the API, EditDocumentXlsxGetRowsAndCells.
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 EditDocumentXlsxGetRowsAndCellsExample{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 GetXlsxRowsAndCellsRequest(); // GetXlsxRowsAndCellsRequest | Document input requesttry{// Get rows and cells from a Excel XLSX spreadsheet, worksheetGetXlsxRowsAndCellsResponse result = apiInstance.EditDocumentXlsxGetRowsAndCells(input);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditDocumentApi.EditDocumentXlsxGetRowsAndCells: " + e.Message );}}}}
And that’s it! So easy. All of our data will be extracted and returned to us in this format:
{
"Successful": true,
"Rows": [
{
"Path": "string",
"Cells": [
{
"Path": "string",
"TextValue": "string",
"CellIdentifier": "string",
"StyleIndex": 0,
"Formula": "string"
}
]
}
]
}
