You are currently offline, serving cached version

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

To insert HTML :

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

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

Initial release

Talk with sales