You are currently offline, serving cached version

Summary

Important : This module only supports xlsx (Excel documents), not docx, see the html if you want to include HTML inside Word documents.

The module also needs the XLSX module to work.

This module currently supports:

  • <a href="URL">Linktext</a>
  • <b>, <u> and <i> tags
  • <strong>, <em> and <span> tags
  • <ul>, <ol>, and <li>
  • <br>
  • font-size: 15px
  • color: #770

To insert HTML :

  • Any tag starting with ~~ is used for block HTML, such as : {~~html} or {~~styledText} which will use the "styledText" data

Usage

Usage (nodejs)

const HTMLXlsxModule = require("docxtemplater-html-xlsx-module");
const XlsxModule = require("docxtemplater-xlsx-module");
const fs = require("fs");

const doc = new Docxtemplater(zip, {
    modules: [new XlsxModule(), new HTMLXlsxModule({})],
}).render({ html: "<b>Hello</b>, Foo !" });

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

fs.writeFile("test.xlsx", buffer);

Usage (browser)

<html>
    <script src="node_modules/docxtemplater/build/docxtemplater.js"></script>
    <script src="node_modules/pizzip/dist/pizzip.js"></script>
    <script src="node_modules/pizzip/vendor/FileSaver.js"></script>
    <script src="node_modules/pizzip/dist/pizzip-utils.js"></script>
    <script src="build/xlsxmodule.js"></script>
    <script src="build/html-xlsx-module.js"></script>
    <script>
        PizZipUtils.getBinaryContent(
            "examples/input.xlsx",
            function (error, content) {
                if (error) {
                    console.error(error);
                    return;
                }

                const zip = new PizZip(content);
                const doc = new docxtemplater(zip, {
                    modules: [
                        new DocxtemplaterXlsxModule(),
                        new DocxtemplaterXlsxHtmlModule({}),
                    ],
                });

                doc.render({
                    html: "<p>Hello <b>John</b></p>",
                });
                const out = doc.getZip().generate({
                    type: "blob",
                    mimeType:
                        "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                });
                saveAs(out, "generated.xlsx");
            }
        );
    </script>
</html>

CHANGELOG

3.1.6

Fix bug when using renderAsync and parser compilation fails : the error should now be shown inside a multierror. To to this, we know use sm.getValueAsync in resolve instead of sm.getValue

3.1.5

Set module.priority in order to have no more issues related to module ordering

3.1.4

Bugfix issue when using expand horizontal loop in xlsx :

TypeError: Cannot read properties of undefined (reading 'fontId')

3.1.3

Bugfix issue when using loop module with HtmlXlsxModule enabled, the following template :

{#items}
{#x}1{/}{#y}2{/y}
{/}

Would produce :

In async mode :

Cannot read properties of undefined (reading 'value')
at ScopeManager._getValue (node_modules/docxtemplater/js/scope-manager.js:43:7)"

In sync mode :

Cannot read properties of undefined (reading 'forEach')
at loopOver (js/index.js)

3.1.2

Add module.clone() internal

3.1.1

Bugfix when passing in empty string : "" or blank string : " ".

Previously, the following error was thrown :

Cannot read properties of undefined (reading 'childNodes')

3.1.0

Add support for :

  • <ul>, <ol>, and <li>
  • <br>
  • font-size: 15px
  • color: #770

Bugfix for <strong>, <em>, <i>, <u>.

3.0.0

Initial release

Talk with sales Contact us