How to get a specific table by index in a Word DOCX document in C# .NET Framework

Extracting specific tables from DOCX files is no one’s idea of fun. That’s OK though, because today we are going to make it about as painless as it can possibly be.

First off, we should activate this command in our Package Manager console, which will use NuGet to retrieve and install the API client that we need.

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

With that out of the way, we are now able to invoke the function EditDocumentDocxGetTableByIndex and provide the 0-based index of the table we desire.

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 EditDocumentDocxGetTableByIndexExample{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 GetDocxTableByIndexRequest(); // GetDocxTableByIndexRequest | Document input requesttry{// Get a specific table by index in a Word DOCX documentGetDocxTableByIndexResponse result = apiInstance.EditDocumentDocxGetTableByIndex(reqConfig);Debug.WriteLine(result);}catch (Exception e){Debug.Print("Exception when calling EditDocumentApi.EditDocumentDocxGetTableByIndex: " + e.Message );}}}}

And that about does it. Sure beats the alternative, doesn’t it?

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