How to Fill Tables in a Word DOCX Document using Node.js

Cloudmersive
2 min readNov 1, 2023

--

Placeholder rows in a DOCX file can be filled seamlessly in our Node.js applications with a quick API request.

Using the ready-to-run Node.js code examples provided further down the page, we can take advantage of a free API that interacts with placeholder values in our DOCX tables. We can structure our request body using data outlined in this example:

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

We can make our request either using the File URL or Form Data, and we can specify our start & end tags before entering our target tag and replacement values in nested cell objects.

To structure our API call, let’s start by installing the SDK. To do so, we can either run the following command:

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

Or we can add this snippet into our package.json:

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

We can then make our API call using the below code, and we can authorize our free requests (up to 800 per month with no additional commitments) with a free-tier Cloudmersvie API key. We can get one of those by registering a free account on the Cloudmersive website.

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.DocxTableTableFillRequest(); // DocxTableTableFillRequest |


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

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet