How to delete a range of table rows in a Word DOCX document in C# .NET Framework

A quick tutorial on how to use an API to delete ranges of table rows from Microsoft Word documents.

Our first step is to install the API Client that we will be calling upon. This is easy enough, simply paste this command into the console of Package Manager.

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

With our API ready to go, we can call the function EditDocumentDocxDeleteTableRowRange as you can see demonstrated below, and specify which rows you would like to remove.

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 EditDocumentDocxDeleteTableRowRangeExample{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 DeleteDocxTableRowRangeRequest(); // DeleteDocxTableRowRangeRequest | Document input requesttry{// Deletes a range of multiple table rows in an existing table in a Word DOCX documentDeleteDocxTableRowRangeResponse result = apiInstance.EditDocumentDocxDeleteTableRowRange(reqConfig);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditDocumentApi.EditDocumentDocxDeleteTableRowRange: " + e.Message );}}}}

That’s it! The rows are gone and your table is ready to go. If you need any other functionality in this same vein, take a look at the other APIs we have available. They cover hundreds of useful features, including format conversion, document editing, and validation.

Image for post

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