Automatically generate Word document from template

From this article, you will learn how to create a document generation process in Plumsail Documents. It will help you to automatically generate any Word DOCX documents from templates, so you can automate document generation in your company.

Particularly in this article, we’ll create invoices. This is how the result document will look:

create docx from template

Let’s go through each step from the very beginning:

Configure Process

First, register or log in to your Plumsail account.

Create new process

Add a new process. You can either create a document generation process from scratch or start from one of premade templates. Let’s create a process from scratch to follow the steps from this instruction.

After we clicked the Add Process button, we need to name our process and select a template type. In our case, it’s DOCX:

create docx from template

Configure template

Once we’ve created the Process, we’ll proceed to its first step - Configure template.

It includes two substeps:

  • Editor;

  • Settings.

In Editor, you can compose the template from scratch or upload an existing one. It’s also possible to modify the uploaded template online.

Feel free to download the invoice DOCX template we have already prepared. Then upload it to the process.

upload template file

Templating syntax

When creating your own templates, mind the templating language. Plumsail Word DOCX templates use a different approach than most other templating solutions. It uses a minimum of syntax to make your work done.

To learn more about the templating engine, check out the documentation article.

In short, the templating engine thinks that everything between such curly {{ }} brackets is variables where it will apply your specified data. In our case the most basic example would be {{invoiceNumber}} and {{date}} tags. They let the engine know that we want to render the invoice number and its date.

But, of course, we can implement a more complex scenario. In our template, we refer to properties inside a collection of products. For that, we use nested tags with a dot operator:

  • The {{product.name}}, {{product.price}} tags get the name, description, and price properties in the product’s object.

The templating engine is smart enough to identify what content to duplicate. It will iterate through all objects in the array to render them and add rows automatically.

tables in DOCX templates

You can learn more about table rendering in the tables section of the documentation.

Test template

To check how the document will look at the end, click on the Test template button. You will see the dialog where you can fill in the auto-generated testing form. Form fields are created from tokens of your document template. You can adjust the look of the testing form by changing token types.

create docx from template

Click on the ‘Create document’, and the resulting invoice will appeat in a new tab. Once you’re satisfied with it, press Save&Next to proceed further - to the Settings substep.

Here you set the following parameters. Descriptions are under the picture.

configure DOCX template

Template mode

It is Testing by default. It means you won’t be charged for this process runs, but result documents will have a Plumsail watermark. Change it to Active to remove the watermark.

Output filename

Use tokens to make it personalized. They work the same way as in the template. For instance, we use the following tokens to define the output file name - {{invoiceNumber}}. As a result, we’ll receive an invoice marked with its number - Invoice 432.

Output type

By default, it is the same as your template’s format. In this particular case, it’s DOCX. And we kept it to create the DOCX Word document from a template.

Test template

Once you’ve customized all the settings, you can test the template to see the result as we did it before.

When everything is done here, click on Save & Next to set up deliveries.

Delivery

The next step is delivery. For demonstrating purpose, we’ll store the result file in OneDrive. But there are other options.

You need to connect to your OneDrive from the Plumsail account. After that, set the folder’s name where to save the ready document. Here you can use tokens as well.

create docx from template

You can configure as many deliveries as you need.

Start Process

Now everything is ready, and you can start generating Word DOCX documents. The step Start process will show available options with a description for each.

start process to create Word from template

You can start the process :