How to delete a range of table rows in a Word DOCX document in Java
1 min readFeb 4, 2020
Deleting rows from a DOCX table should be a snap, right? Well, if you are following anyone else’s tutorial, this might not actually be the case. Luckily, you came to the right place, and you’ll be done with this in just a matter of minutes!
To begin with, we will use Jitpack to dynamically compile our API library. This means inserting two snippets into our Maven POM file:
Repository
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Dependency
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.34</version>
</dependency>
</dependencies>
With our library ready, we can invoke editDocumentDocxDeleteTableRowRange using this sample code below:
// 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();DeleteDocxTableRowRangeRequest reqConfig = new DeleteDocxTableRowRangeRequest(); // DeleteDocxTableRowRangeRequest | Document input requesttry {DeleteDocxTableRowRangeResponse result = apiInstance.editDocumentDocxDeleteTableRowRange(reqConfig);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling EditDocumentApi#editDocumentDocxDeleteTableRowRange");e.printStackTrace();}