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 :
~~
is used for block HTML, such as : {~~html}
or {~~styledText}
which will use the "styledText" dataconst 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);
<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>
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
Set module.priority in order to have no more issues related to module ordering
Bugfix issue when using expand horizontal loop in xlsx :
TypeError: Cannot read properties of undefined (reading 'fontId')
Bugfix issue when using loop module with HtmlXlsxModule enabled, the following template :
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)
Add module.clone() internal
Bugfix when passing in empty string : ""
or blank string : " "
.
Previously, the following error was thrown :
Cannot read properties of undefined (reading 'childNodes')
Add support for :
<ul>
, <ol>
, and <li>
<br>
font-size: 15px
color: #770
Bugfix for <strong>
, <em>
, <i>
, <u>
.
Initial release