How to get worksheets from an Excel XLSX spreadsheet in C# .NET Framework

Today we are going to lay out steps for retrieving worksheet tabs from an XLSX file in .NET Framework. Don’t worry, this is going to be easy as pie.

Client installation is first on our agenda. Open the console of Package Manager and drop in this command:

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

With our API client ready to go, we simply input our XLSX file into EditDocumentXlsxGetWorksheets:

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 EditDocumentXlsxGetWorksheetsExample{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 GetXlsxWorksheetsRequest(); // GetXlsxWorksheetsRequest | Document input requesttry{// Get worksheets from a Excel XLSX spreadsheetGetXlsxWorksheetsResponse result = apiInstance.EditDocumentXlsxGetWorksheets(input);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditDocumentApi.EditDocumentXlsxGetWorksheets: " + e.Message );}}}}

And now our API will return the worksheets found in the file. Easy. If you enjoyed this simplified technique, take a moment and browse our other tutorials for similar functions.

Image for post
Image for post

Written by

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store