How to Fill Data in Multiple Word DOCX Placeholder Tables using Node.js

Cloudmersive
2 min readDec 6, 2023

--

Dynamic data entry within open standard document formats like DOCX depends on an in-depth understanding of the file structure in question. Thankfully, when we use specialized APIs to build out our file processing applications, we don’t have to spend precious time learning DOCX file structure OR writing new code from scratch.

Using the ready-to-run code examples provided below, we can take advantage of a free API that allows us to fill placeholder rows in our DOCX tables using one (or more) templates. This will make it easy to dynamically fill DOCX tables in placeholder documents with new values based on individual client-side requests. Our request object can look like the application/JSON example below:

{
"InputFileUrl": "string",
"InputFileData": "string",
"TablesToFill": [
{
"TableStartTag": "string",
"TableEndTag": "string",
"DataToFillIn": [
{
"Cells": [
{
"TargetTag": "string",
"ReplacementValue": "string"
}
]
}
]
}
]
}

To authorize our API calls for free, we’ll just need a free-tier API key — this will allow us to make up to 800 API calls per month with no additional commitment.

We can begin structuring our API call by installing the SDK. Let’s either install using NPM install:

npm install cloudmersive-convert-api-client --save

Or let’s add the Node client to our package.json instead:

  "dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}

After that, let’s copy the below code into our file and customize our request according to our placeholder document:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;

// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';



var apiInstance = new CloudmersiveConvertApiClient.TransformDocumentApi();

var request = new CloudmersiveConvertApiClient.DocxTableTableFillMultiRequest(); // DocxTableTableFillMultiRequest |


var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.transformDocumentDocxTableFillInMulti(request, callback);

Now we can dynamically fill multiple DOCX tables with a single API request.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet