How to apply a Word DOCX Template in Node.JS

Today I’m going to show you how to fill in a DOCX template with data using Node.JS. This is going to be super quick, so let’s get straight to it.

Beginning with installation, we can use this command to set up our API client.

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

Proceeding onward, we call the function below for DOCX templating. Now we can enter in our templateDefinition to be used, and also our inputFile with the desired data.

var apiInstance = new CloudmersiveConvertApiClient.ConvertTemplateApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var opts = {'templateDefinition': null // Object | Template definition for the document, including what values to replace};var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertTemplateApplyDocxTemplate(inputFile, opts, callback);

OK, we are done. Our template will be applied to the inputFile and we can all move on to more important things! If this handy shortcut saved you some time, check out more functions in this API, as they cover a whole range of different document and format related actions.

Image for post
Image for post

Written by

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