How to remove a worksheet from an Excel XLSX spreadsheet in C# .NET Framework

Cloudmersive
1 min readFeb 21, 2020

--

This quick tutorial will get you up to speed on how to remove individual worksheets from an XLSX file.

We can install the API client we need with NuGet if we run this command in our package console.

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

Moving right along, we can invoke EditDocumentXlsxDeleteWorksheet:

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 EditDocumentXlsxDeleteWorksheetExample{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 reqConfig = new RemoveXlsxWorksheetRequest(); // RemoveXlsxWorksheetRequest | Spreadsheet input requesttry{// Delete, remove worksheet from an Excel XLSX spreadsheet documentObject result = apiInstance.EditDocumentXlsxDeleteWorksheet(reqConfig);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditDocumentApi.EditDocumentXlsxDeleteWorksheet: " + e.Message );}}}}

Done! Our desired worksheet has now been removed from our spreadsheet. A useful companion function for this is EditDocumentXlsxGetWorksheets, which numbers and lists all worksheets in an Excel file.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet