Releases RSS Feed
Compatibility : nodejs and browser

Summary (version 3.5.3) Buy table module

This module makes it easy to create a table from a configuration object (header, subheader, ...)

This module is available as part of the docxtemplater ENTREPRISE plan.


Table Module

This module exposes multiple tags to create or transform tables.

Currently, you can

  • create a table from scratch with the{:table table1} syntax,
  • Loop over table columns with the {:vt#users} {:vt/users} syntax


You will need docxtemplater v3: npm install docxtemplater

Install this module with npm install --save "$url"

Vertical Loop Table

To have the vertical-loop-table, write :

const TableModule = require("docxtemplater-table-module");
doc.attachModule(new TableModule.Vertical())

To create a vertical loop table, you just have to use the {:vt#users} {:vt/users} tags, for example

Table {:vt#users}
Name {name}
Age {age}
Address {address}{:vt/users}

This will create a column for each user in the users array.

It will completely remove the column if users is false or empty.

Full Table


Your docx should contain the text: {:table table1}. You can find a working sample at ./sample.js


To have the vertical-loop-table, write :

const TableModule = require("docxtemplater-table-module");
doc.attachModule(new TableModule.Full())

When creating the table, you have multiple options :

  • fixedColumns: Example : [null, "Example 1", null, "Example 2"] : This option defines the columns that should take the whole height of the table
  • widths : Example [100, 150, 320, 100] : This option defines the width of each colum
  • totalWidth : This option cannot be used together with widths. if you use totalWidth, the width of each cell will be the totalWidth divided by the number of columns. For example, you can set totalWidth to 700 and have 2 columns of each width 350. It is also possible to set a width as a percentage with a string (for example : totalWidth: "80%". When using percentages, the current page layout will be taken into account, to have the table width depend on the page layout.
  • header : Example ["Source", "Hazard", "Handling", "Protection"] : This option defines the header of the table (in bold)
  • subheader: Example ["The source", "The Hazard", "The Handling", "The Protection"] : This option defines the subheader of the table (in italic)
  • chunkSize: Example : 6 : This option defines the number of lines after which to break the table into multiple tables

You can also have dynamic chunkSize, for example:

chunkSize: {
    type: "dynamic",
    size: { min: 7000, max: 8100},

This means that the height of the table will never exceed 8100 (the max). If the table exceeds the min, the next line will be in a new table. The unit is an internal word unit.

  • data : Example :

    data: [
        ["A1", "lorem"],
        ["B1", "lorem"],
        ["C1", "lorem"],

    This option defines the data of the table.

  • border: Example : { type: "all", size: 5, color: "000000"} : This option defines the borders that are around each cell.

Global Options

It is possible to have global options for all tables created in the document, for example, to have all tables center-aligned :

const options = { align: "center" };
doc.attachModule(new TableModule.Full(options));

If options is an object, it will be merge with the default options.

It is also possible to pass a function here which gets the default options as an argument, and returns the used options.

For example, to remove the default spacingAfter of 200, you can write

const options = function(defaultOptions) {
    return {};
doc.attachModule(new TableModule.Full(options));

Grid Layout

It is possible to create a grid layout like this :

grid-template Grid template

Which will be rendered like this :

grid-template Grid template

In your code, do the following

const TableModule = require("docxtemplater-table-module");
doc.attachModule(new TableModule.Grid())
    user: {
        size: [2, 4], // means 2 lines, 4 columns
        widths: [175, 175, 175, 175], // The widths of each column
        height: 200, // The height of each column
        data: [
                index: 1,
                name: "John",
                title: "Foobar",
                description: "3374 Olen Thomas Drive Frisco Texas 75034",
                index: 2,
                name: "Mary",
                title: "Foobaz",
                description: "352 Illinois Avenue Yamhill Oregon(OR) 97148",



Keep same font-size of text in {:table table1}


  • Update browser build to use XMLSerializer instead of xmldom

  • Use requiredAPIVersion


Add option border : { type: "all"} to force to have borders.

Fix bug totalWidth float


Add possibility to specify totalWidth, for example totalWidth: 700 or totalWidth: '100%'.

Add table grid module using : {:#grid user} and {:/grid}


  • Move docxtemplater from devDependencies to dependencies

Explanation : On some versions of npm (notably 5.8.0), when having a package containing docxtemplater-table-module, the installation will generate a tree of node_modules that puts the module on a level where it has no access to docxtemplater. By explicitly asking it as a dependency, this issue is avoided.


Make it possible to not have a subheader (header without subheader)


  • Make module compatible with docxtemplater version 3.5 and below.

Explanation : Recently, the scopemananger API (internal API) has changed, this new version of the footnotes module makes the module work with both versions newer than 3.6 and older than 3.6 of docxtemplater.


Add meta context argument to custom parser with information about the tag for each types of tags


For Full Table module, add possibility to add function in constructor to be able to customize the default spacingAfter property (eg for example, remove any default options).


For Full Table module, use style and properties of current paragraph for each cells in the paragraphs.


For Full Table module, Add possibility to :

  • set the alignment with the align option

  • set options global to each table in the constructor


For Full Table module, make all parameters except data optional.


Handle vertical tables that have different amount of columns. For example :

Table {:vt#users}
name (The name of the user) {name}
address (The address of the user) {address}{:vt/users}


Make generated docx not contain unnecessary commas


Add support for vertical table


  • Add table style only if needed


  • Fix other .forEach when last table is empty.
  • Fix height calculation, that doesn't take into account the height of the vertical cells


The headerSize is now calculated and taken into account when chunking.

Fix .forEach bug : If the dataset contains a cell that would not fit in the table because it is too high, the module will still put it in there since it cannot be splitted


Add support for dynamic chunkSize.

You can write :

chunkSize: {
    type: "dynamic",
    size: { min: 7000, max: 8100},


Initial release

Edgar Hipp

I'm the creator of docxtemplater. I work on making docxtemplater great since 2013.