How to Fill Data for Multiple Tables in a DOCX Document & Return the Result using Java
Using placeholder rows within DOCX files makes it possible for users to customize a standardized document via client-side data entry. Our DOCX data filler API facilitates this process, communicating with placeholder rows and filling them with new values seamlessly. Thankfully, it’s both free and easy to take advantage of this API. You can install the API client & structure your API call using the Java code examples below; in order to authenticate the operation, you’ll just need to register a free account on our website & copy our free-tier API key where indicated in the documentation.
We can begin installing the API client with Maven by first adding a reference to the pom.xml repository:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
And then adding one to the pom.xml dependency:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>
Moving onto the controller — we can include the below imports at the top of our file:
// 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.TransformDocumentApi;
Now we can call the function using the below examples, and we’re all set:
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth 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");TransformDocumentApi apiInstance = new TransformDocumentApi();
DocxTableTableFillMultiRequest request = new DocxTableTableFillMultiRequest(); // DocxTableTableFillMultiRequest |
try {
byte[] result = apiInstance.transformDocumentDocxTableFillInMulti(request);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling TransformDocumentApi#transformDocumentDocxTableFillInMulti");
e.printStackTrace();
}
Below, I’ve included a sample (JSON) response model for your reference:
{
"InputFileUrl": "string",
"InputFileData": "string",
"TablesToFill": [
{
"TableStartTag": "string",
"TableEndTag": "string",
"DataToFillIn": [
{
"Cells": [
{
"TargetTag": "string",
"ReplacementValue": "string"
}
]
}
]
}
]
}