node-red-contrib-xlsx-template-tienho 2.0.0

Allow to generate XLSX reports

npm install node-red-contrib-xlsx-template-tienho

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.payload can now be a plain JavaScript object. You do not need to call JSON.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, missing msg.report, and invalid msg.sheet are validated before reading or writing files.
  • File writing now uses async fs.writeFile() instead of fs.writeFileSync().
  • Removed the unnecessary fs npm dependency because fs is built into Node.js.
  • Fixed package.json main to point to xlsx-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.payload is empty or not valid JSON/object data, the node reports an error and returns.
  • If msg.template is missing or unreadable, the node reports an error and returns.
  • If msg.report is missing or cannot be written, the node reports an error and returns.
  • If msg.sheet is 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.

Node Info

Version: 2.0.0
Updated 1 week, 5 days ago
License: MIT
Rating: 5.0 1

Categories

Actions

Rate:

Downloads

5 in the last week

Nodes

  • xlsx-template-tienho

Keywords

  • xlsx
  • templates
  • node-red

Maintainers