@platmac/node-red-docxtemplater2
v1.0.1
Published
Generate docx, pptx, and xlsx from templates (Word, Powerpoint and Excel documents), from Node-Red using file from url or buffer
Downloads
71
Maintainers
Readme
node-red-contrib-docxtemplater
node-red-contrib-docxtemplater
is a Node-RED node that enables you to generate Word documents (.docx) by dynamically filling templates using Docxtemplater. With this node, you can create rich, personalized Word documents directly from Node-RED, making it ideal for report generation, invoices, and custom documents.
Installation
To install, run the following command in your Node-RED directory:
npm install omerkaptan/node-red-contrib-docxtemplater
Usage
- Template Creation: Start by creating a
.docx
template with placeholders formatted as tags, like{{name}}
,{{date}}
, or{{items}}
. Tags are placeholders that Docxtemplater will replace with actual values. - Template Input: Provide the
.docx
template to the node, either as a file path or binary input. - Data Input: Send data as a JSON object, mapping each tag to a value (e.g.,
{ "name": "Alice", "date": "2024-10-30" }
). - Output: The node outputs a
.docx
document where each placeholder is replaced by the data you've provided.
Examples
Here are some specific tag usage examples you can use with your .docx
templates:
Simple Text Replacement: Replace
{{name}}
with a name:{ "name": "Alice" }
Looping Over Arrays: To add a list of items in a table format, use the
{{#items}}...{{/items}}
tag structure in your.docx
template, and pass an array of objects as shown below:{ "items": [ { "description": "Item 1", "price": 10 }, { "description": "Item 2", "price": 15 } ] }
Conditional Tags: Use conditional tags to show or hide content based on a value:
{ "isApproved": true }
In your template, use tags like
{{#isApproved}}Approved{{/isApproved}}
to display "Approved" only ifisApproved
is true.
For more advanced tag types and formatting options, see the full Docxtemplater Tag Types documentation.
Example Flow
- Template Node: Use a file input node to load the
.docx
template. - Data Node: Add a JSON node with the structured data to fill in placeholders.
- Docxtemplater Node: Connect the template and data nodes to the
docxtemplater
node. - Output Node: Use a file output node to save the generated
.docx
document.
Dependencies
This node depends on Docxtemplater for template processing, so refer to their documentation for further customization options.
License
MIT License