How to get a specific table by index in a Word DOCX document in Java

In this tutorial we have for you today a nice, easy method for extracting specific tables from Microsoft Word DOCX files. Rather than undergo the unforgiving task of parsing these files directly and trying to identify table data, we will rather be opting for use of an API. This will allow us to get everything done quickly and be home in time for dinner.

Let us begin with our references. First, we need this repository reference for Jitpack, which will allow us to compile our library.


And follow that with a dependency reference for the library itself.


OK, moving right along, we have our function call.

// Import classes://import com.cloudmersive.client.invoker.ApiClient;//import com.cloudmersive.client.invoker.ApiException;//import com.cloudmersive.client.invoker.Configuration;//import com.cloudmersive.client.invoker.auth.*;//import com.cloudmersive.client.EditDocumentApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");Apikey.setApiKey("YOUR API KEY");// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.setApiKeyPrefix("Token");EditDocumentApi apiInstance = new EditDocumentApi();GetDocxTableByIndexRequest reqConfig = new GetDocxTableByIndexRequest(); // GetDocxTableByIndexRequest | Document input requesttry {GetDocxTableByIndexResponse result = apiInstance.editDocumentDocxGetTableByIndex(reqConfig);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling EditDocumentApi#editDocumentDocxGetTableByIndex");e.printStackTrace();}

And believe it or not, that’s the entire setup process! Done.

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