Demo
Readme
Changelog
Releases RSS Feed
Compatibility : nodejs and browser

Summary (version 3.1.3) Buy styling module

This module makes it possible to edit style of table cells or paragraphs conditionnaly (background-color, ...).

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

README

Style Module

This module exposes multiple tags to dynamically change the style of a given paragraph or table cell for example.

The current tags are :

  • {:stylecell style} To style a cell
  • {:stylepar style} To style a paragraph

Installation:

You will need docxtemplater v3: npm install docxtemplater

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

Usage

Your docx should contain the text: {:stylecell style}.

const StyleModule = require("./es6");
const styleModule = new StyleModule();
const JSZip = require("jszip");
const zip = new JSZip(content);
const docx = new DocxTemplater()
    .attachModule(styleModule)
    .loadZip(zip)
    .setData({
        style: {
            cellBackground: "#00ff00",
            textColor: "white"
            fontFamily: "Calibri"
        }
    });

docx.render();
const buffer = docx.getZip().generate({compression: "DEFLATE", type: "nodebuffer"});

After installing the module, you can use a working demo by running node sample.js.

CHANGELOG

3.1.3

  • Move docxtemplater from devDependencies to dependencies

Explanation : On some versions of npm (notably 5.8.0), when having a package containing docxtemplater-styling-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.

3.1.2

  • 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.

3.1.1

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

3.1.0

  • Add the {:stylepar style} tag to change the paragraph style

  • Add support for fontFamily: "Calibri"

  • Refactor module.prefix into an object {cell: ':stylecell', paragraph: ':stylepar'}

3.0.0

Initial release

Edgar Hipp

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