You are currently offline, serving cached version

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
  • {:stylerow style} To style a whole row in a table

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

Usage (nodejs)

const StyleModule = require("./es6/index.js");
const styleModule = new StyleModule();
const PizZip = require("pizzip");
const zip = new PizZip(content);
const doc = new Docxtemplater(zip, { modules: [styleModule] });
doc
    .setData({
        style: {
            cellBackground: "#00ff00",
            textColor: "white"
            fontFamily: "Calibri"
        }
    });

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

Paragraph Styling

To style a paragraph, you can use following styles :

{
    "cellBackground": "#00ff00",
    "textColor": "white",
    "pStyle": "Heading",
    "fontFamily": "Calibri"
}

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

CHANGELOG

3.3.6

Use @xmldom/xmldom instead of xmldom, see this github issue

3.3.5

Generate files in built with correct filename In previous versions, the filename was always build/docxtemplater.js. Now the filename is error-location-module.js The .min.js file is also created now.

3.3.4

Add typescript definitions for public API

3.3.3

Move webpack from dependency to devDependency (which triggered an error during installation on node version 10)

3.3.2

Internal change to allow to match tags with non-breaking space.

When entering Ctrl+Shift+Space, a "non-breaking" space is created.

When using a non-breaking space in the tag {:stylecell style}, the tag would not be replaced correctly.

3.3.1

Update to make module work in the browser

3.3.0

Add support for pptx

Add {:stylerow} tag

Require docxtemplater 3.17.6

3.2.1

Declare supportedFileTypes, which allows to use this module with the new docxtemplater constructor which was introduced in docxtemplater 3.17.

3.2.0

  • Add support for changing pStyle in {:stylepar}

3.1.4

  • Update browser build to use XMLSerializer instead of xmldom

  • Use requiredAPIVersion

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