node-red-contrib-xlsx-template-tienho 2.0.0
Allow to generate XLSX reports
Node-RED XLSX Template Tienho
Node-RED node for generating XLSX reports from an XLSX template using
xlsx-template.
Version 2.0.0 notes
msg.payloadcan now be a plain JavaScript object. You do not need to callJSON.stringify()before sending data to this node.- JSON strings are still supported for backward compatibility.
- Buffer payloads containing JSON text are also supported.
- Invalid payloads are reported with
node.error(..., msg)and the node stops processing the current message safely. - Missing
msg.template, missingmsg.report, and invalidmsg.sheetare validated before reading or writing files. - File writing now uses async
fs.writeFile()instead offs.writeFileSync(). - Removed the unnecessary
fsnpm dependency becausefsis built into Node.js. - Fixed
package.jsonmainto point toxlsx-template-tienho.js.
Inputs
msg.payload
Data used to fill placeholders in the XLSX template.
Recommended format:
msg.payload = {
customerName: "Nguyen Van A",
invoiceNo: "INV-001",
total: 1250000,
items: [
{ name: "Product A", qty: 2, price: 300000 },
{ name: "Product B", qty: 1, price: 650000 }
]
};
Backward-compatible JSON string format:
msg.payload = JSON.stringify({
customerName: "Nguyen Van A",
invoiceNo: "INV-001",
total: 1250000
});
msg.template
Full path to the XLSX template file.
msg.template = "D:/templates/invoice-template.xlsx";
msg.report
Full path where the generated XLSX report will be saved.
msg.report = "D:/reports/invoice-output.xlsx";
msg.sheet
Optional sheet number. Defaults to 1.
msg.sheet = 1;
Function node example
msg.payload = {
customerName: "Nguyen Van A",
invoiceNo: "INV-001",
date: "2026-05-10",
total: 1250000,
items: [
{ name: "Product A", qty: 2, price: 300000 },
{ name: "Product B", qty: 1, price: 650000 }
]
};
msg.template = "D:/templates/invoice-template.xlsx";
msg.report = "D:/reports/invoice-output.xlsx";
msg.sheet = 1;
return msg;
Template placeholders
Use placeholders supported by the original
xlsx-template package.
Example placeholders in the XLSX template:
${customerName}
${invoiceNo}
${total}
For array/table usage, follow the xlsx-template placeholder syntax.
Error handling notes
The node validates input before processing:
- If
msg.payloadis empty or not valid JSON/object data, the node reports an error and returns. - If
msg.templateis missing or unreadable, the node reports an error and returns. - If
msg.reportis missing or cannot be written, the node reports an error and returns. - If
msg.sheetis not a positive integer, the node reports an error and returns.
These errors should not stop the whole Node-RED runtime. They are reported on the current message through Node-RED's normal node error mechanism.
Install from local tarball
After packing this module, install the generated .tgz file from your Node-RED
user directory:
npm install /path/to/node-red-contrib-xlsx-template-tienho-2.0.0.tgz
Then restart Node-RED.