Here is a simple flow to use carbone.io template

the first inject node contains data
{
"entetes": [
{
"hdr": "col 1",
"valeur": "Colonne 1"
},
{
"hdr": "col 2",
"valeur": "Colonne 2"
},
{
"hdr": "col 3",
"valeur": "Colonne 3"
}
],
"data": [
{
"hdr": [
{
"hdr": "col 1",
"valeur": "A 1"
},
{
"hdr": "col 2",
"valeur": "A 2"
},
{
"hdr": "col 3",
"valeur": "A 3"
}
]
},
{
"hdr": [
{
"hdr": "col 1",
"valeur": "B 1"
},
{
"hdr": "col 2",
"valeur": "B 2"
},
{
"hdr": "col 3",
"valeur": "B 3"
}
]
},
{
"hdr": [
{
"hdr": "col 1",
"valeur": "C 1"
},
{
"hdr": "col 2",
"valeur": "C 2"
},
{
"hdr": "col 3",
"valeur": "C 3"
}
]
}
]
}
in output, there is a buffer with 12510 bytes, and the conversion with carbone.io is ok

the second inject node does not contain data. But data are set in the function node
const obj = {
entetes:[
{hdr:"col 1",valeur:"Colonne 1"},
{hdr:"col 2",valeur:"Colonne 2"},
{hdr:"col 3",valeur:"Colonne 3"}
],
"data":[
{hdr:[
{hdr:"col 1",valeur:"A 1"},
{hdr:"col 2",valeur:"A 2"},
{hdr:"col 3",valeur:"A 3"}
]},
{hdr:[
{hdr:"col 1",valeur:"B 1"},
{hdr:"col 2",valeur:"B 2"},
{hdr:"col 3",valeur:"B 3"}
]},
{hdr:[
{hdr:"col 1",valeur:"C 1"},
{hdr:"col 2",valeur:"C 2"},
{hdr:"col 3",valeur:"C 3"}
]}
]
};
msg.payload = obj;
return msg;
and now, the output is a buffer with 12044 bytes, and of course, the conversion with carbone.io does not work.
![]()
Any idea ? I am totally lost ! I do not understand why the same data provided in tow different ways does not give the same result !
Thanks for your help
Here is the complete flow
[
{
"id": "22f7a47b705ecce9",
"type": "subflow",
"name": "carbone.io",
"info": "",
"category": "",
"in": [
{
"x": 360,
"y": 220,
"wires": [
{
"id": "86a74d51bfadf18d"
}
]
}
],
"out": [
{
"x": 840,
"y": 220,
"wires": [
{
"id": "bec126f7ce06bed5",
"port": 0
}
]
}
],
"env": [],
"meta": {},
"color": "#DDAA99"
},
{
"id": "86a74d51bfadf18d",
"type": "function",
"z": "22f7a47b705ecce9",
"name": "carbone.io",
"func": "const carbone = global.get('carbone');\nlet donnees = msg.payload;\nconst template = msg.template;\n\n//carbone.render('.node-red/node_modules/carbone/examples/simple.docx', data, function (err, result) {\ncarbone.render(template, donnees, function (err, result) {\n if (err) {\n msg.payload = err;\n node.send(msg);\n console.log(err)\n return msg;\n }\n // write the result\n console.log(\"resultat \",result);\n msg.payload = result;\n node.send(msg);\n});\n\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 490,
"y": 220,
"wires": [
[
"bec126f7ce06bed5"
]
]
},
{
"id": "bec126f7ce06bed5",
"type": "file",
"z": "22f7a47b705ecce9",
"name": "",
"filename": "filename",
"filenameType": "msg",
"appendNewline": false,
"createDir": false,
"overwriteFile": "true",
"encoding": "none",
"x": 700,
"y": 220,
"wires": [
[]
]
},
{
"id": "61659a935ce4e0e3",
"type": "comment",
"z": "22f7a47b705ecce9",
"name": "Contenu du msg",
"info": "msg.payload : data\nmsg.template : template\nmsg.filename : filename",
"x": 640,
"y": 160,
"wires": []
},
{
"id": "d3fdf49a4cdea52c",
"type": "subflow:22f7a47b705ecce9",
"z": "d09f90d38227a234",
"g": "4566950462049265",
"name": "",
"x": 670,
"y": 680,
"wires": [
[
"d6d9644d034ef075"
]
]
},
{
"id": "55092a8cda98d291",
"type": "inject",
"z": "d09f90d38227a234",
"g": "4566950462049265",
"name": "with data",
"props": [
{
"p": "template",
"v": "C:\\Users\\Serge\\Documents\\#04 DB_SCENO\\Modeles\\carboneNomenclature.docx",
"vt": "str"
},
{
"p": "filename",
"v": "C:\\Users\\Serge\\Documents\\#04 DB_SCENO\\Modeles\\carbone.docx",
"vt": "str"
},
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{\"entetes\":[{\"hdr\":\"col 1\",\"valeur\":\"Colonne 1\"},{\"hdr\":\"col 2\",\"valeur\":\"Colonne 2\"},{\"hdr\":\"col 3\",\"valeur\":\"Colonne 3\"}],\"data\":[{\"hdr\":[{\"hdr\":\"col 1\",\"valeur\":\"A 1\"},{\"hdr\":\"col 2\",\"valeur\":\"A 2\"},{\"hdr\":\"col 3\",\"valeur\":\"A 3\"}]},{\"hdr\":[{\"hdr\":\"col 1\",\"valeur\":\"B 1\"},{\"hdr\":\"col 2\",\"valeur\":\"B 2\"},{\"hdr\":\"col 3\",\"valeur\":\"B 3\"}]},{\"hdr\":[{\"hdr\":\"col 1\",\"valeur\":\"C 1\"},{\"hdr\":\"col 2\",\"valeur\":\"C 2\"},{\"hdr\":\"col 3\",\"valeur\":\"C 3\"}]}]}",
"payloadType": "json",
"x": 280,
"y": 680,
"wires": [
[
"d3fdf49a4cdea52c"
]
]
},
{
"id": "f0b28ec8f335eb58",
"type": "function",
"z": "d09f90d38227a234",
"g": "4566950462049265",
"name": "function 3",
"func": "const obj = {\n entetes:[\n {hdr:\"col 1\",valeur:\"Colonne 1\"},\n {hdr:\"col 2\",valeur:\"Colonne 2\"},\n {hdr:\"col 3\",valeur:\"Colonne 3\"}\n ],\n \"data\":[\n {hdr:[\n {hdr:\"col 1\",valeur:\"A 1\"},\n {hdr:\"col 2\",valeur:\"A 2\"},\n {hdr:\"col 3\",valeur:\"A 3\"}\n ]},\n {hdr:[\n {hdr:\"col 1\",valeur:\"B 1\"},\n {hdr:\"col 2\",valeur:\"B 2\"},\n {hdr:\"col 3\",valeur:\"B 3\"}\n ]},\n {hdr:[\n {hdr:\"col 1\",valeur:\"C 1\"},\n {hdr:\"col 2\",valeur:\"C 2\"},\n {hdr:\"col 3\",valeur:\"C 3\"}\n ]}\n ]\n};\nmsg.payload = obj;\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 460,
"y": 740,
"wires": [
[
"d3fdf49a4cdea52c"
]
]
},
{
"id": "3c08e9e4db56bae6",
"type": "inject",
"z": "d09f90d38227a234",
"g": "4566950462049265",
"name": "without data",
"props": [
{
"p": "template",
"v": "C:\\Users\\Serge\\Documents\\#04 DB_SCENO\\Modeles\\carboneNomenclature.docx",
"vt": "str"
},
{
"p": "filename",
"v": "C:\\Users\\Serge\\Documents\\#04 DB_SCENO\\Modeles\\carbone.docx",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 290,
"y": 740,
"wires": [
[
"f0b28ec8f335eb58"
]
]
}
]
