# Problem to var require = global.get('require'); - 3 scheet to 1 xlsx

**URL:** <https://discourse.nodered.org/t/problem-to-var-require-global-get-require-3-scheet-to-1-xlsx/98195>\
**Category:** General\
**Tags:** function-node\
**Created:** [18 July 2025 07:29 UTC](https://discourse.nodered.org/t/problem-to-var-require-global-get-require-3-scheet-to-1-xlsx/98195 "2025-07-18T07:29:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BaNod-Red](https://avatars.discourse-cdn.com/v4/letter/b/9f8e36/32.png) [@BaNod-Red](https://discourse.nodered.org/u/BaNod-Red)\
**Post date:** [18 July 2025 07:29 UTC](https://discourse.nodered.org/t/problem-to-var-require-global-get-require-3-scheet-to-1-xlsx/98195/1 "2025-07-18T07:29:30Z")

</div>

Want to use 3 queries and feed 3 sheets in excel all the time I have an error  
var require = global.get('require');

I corrected in settings file  
Nothing helped  
or maybe some quick solution what to change in code ?

```auto
[
    {
        "id": "184a71d3.6af50e",
        "type": "function",
        "z": "47d8dd38b03906ea",
        "name": "",
        "func": "\nmsg.attachments= [\n { \n filename: msg.filename,\n content: msg.excel,\n encoding: 'base64'\n }\n]\n\n// if (msg.ZalaczRaportDoTresci === true)\n// {\n// msg.body = msg.payload;\n// }\n// else \n// {\n// msg.body = msg.wiadomosc;\n// }\n\nmsg.before= msg.wiadomosc;\n\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "x": 1065,
        "y": 180,
        "wires": [
            []
        ],
        "l": false
    },
    {
        "id": "33bd0017.24fa4",
        "type": "tableify",
        "z": "47d8dd38b03906ea",
        "name": "",
        "before": "",
        "after": "",
        "tableStyle": "",
        "theadStyle": "",
        "tbodyStyle": "",
        "trStyle": "",
        "tdStyle": "",
        "x": 1005,
        "y": 180,
        "wires": [
            [
                "184a71d3.6af50e"
            ]
        ],
        "l": false
    },
    {
        "id": "2206a863.9f2928",
        "type": "function",
        "z": "47d8dd38b03906ea",
        "name": "config",
        "func": "msg.to = msg.mail[0].email;\nmsg.cc = 'test@test.com';\n\n\nmsg.topic='Test join xlsx to scheet nr:' ;\nmsg.filename = 'Test.xlsx';\n\nmsg.wiadomosc = 'Test Raports'; \nmsg.scheet1 = 'scheet1';\nmsg.scheet2 = 'scheet2';\nmsg.scheet3 = 'scheet3';\n\nmsg.before= \n\n`\nTest Raports\n\n\n`\n\n \n\n\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 780,
        "y": 180,
        "wires": [
            [
                "2515b35f.ff580c"
            ]
        ]
    },
    {
        "id": "7549c41c.03690c",
        "type": "function",
        "z": "47d8dd38b03906ea",
        "name": "",
        "func": "msg.tableStyle=`{\n border: 1px solid #1C6EA4;\n background-color: #EEEEEE;\n width: 100%;\n text-align: left;\n border-collapse: collapse;\n}`\n\nmsg.theadStyle=` background: #1C6EA4;\n background: -moz-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);\n background: -webkit-linear-gradient(top, #5592bb 0%, #327cad 66%, #1C6EA4 100%);\n background: linear-gradient(to bottom, #5592bb 0%, #327cad 66%, #1C6EA4 100%);\n border-bottom: 2px solid #444444;`;\n\nmsg.tbodyStyle=`font-size: 13px;`\n\nmsg.trStyle=`border: 1px solid #AAAAAA; padding: 3px 2px;`;\n\nmsg.tdStyle=`border: 1px solid #AAAAAA; padding: 3px 2px;`;\n\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 945,
        "y": 180,
        "wires": [
            [
                "33bd0017.24fa4"
            ]
        ],
        "l": false
    },
    {
        "id": "c46a7807.a07ad8",
        "type": "MSSQL",
        "z": "47d8dd38b03906ea",
        "mssqlCN": "",
        "name": "",
        "outField": "raport02",
        "returnType": "0",
        "throwErrors": "0",
        "query": "\nselect \n Test 1 \nFrom Test 1",
        "modeOpt": "",
        "modeOptType": "query",
        "queryOpt": "",
        "queryOptType": "editor",
        "paramsOpt": "queryParams",
        "paramsOptType": "msg",
        "rows": "",
        "rowsType": "msg",
        "parseMustache": true,
        "params": [],
        "x": 305,
        "y": 180,
        "wires": [
            [
                "10186f43.66ff81"
            ]
        ],
        "l": false
    },
    {
        "id": "10186f43.66ff81",
        "type": "MSSQL",
        "z": "47d8dd38b03906ea",
        "mssqlCN": "",
        "name": "",
        "outField": "raport03",
        "returnType": "0",
        "throwErrors": "0",
        "query": "\nselect \n Test 2\nFrom Test 2",
        "modeOpt": "",
        "modeOptType": "query",
        "queryOpt": "",
        "queryOptType": "editor",
        "paramsOpt": "queryParams",
        "paramsOptType": "msg",
        "rows": "",
        "rowsType": "msg",
        "parseMustache": true,
        "params": [],
        "x": 365,
        "y": 180,
        "wires": [
            [
                "31d0d7cc.138488"
            ]
        ],
        "l": false
    },
    {
        "id": "31d0d7cc.138488",
        "type": "MSSQL",
        "z": "47d8dd38b03906ea",
        "mssqlCN": "",
        "name": "",
        "outField": "raport04",
        "returnType": "0",
        "throwErrors": "0",
        "query": "\nselect \n Test 3 \nFrom Test 3",
        "modeOpt": "",
        "modeOptType": "query",
        "queryOpt": "",
        "queryOptType": "editor",
        "paramsOpt": "queryParams",
        "paramsOptType": "msg",
        "rows": "",
        "rowsType": "msg",
        "parseMustache": true,
        "params": [],
        "x": 425,
        "y": 180,
        "wires": [
            [
                "2206a863.9f2928"
            ]
        ],
        "l": false
    },
    {
        "id": "2515b35f.ff580c",
        "type": "function",
        "z": "47d8dd38b03906ea",
        "name": "exceljs",
        "func": "msg.payload = msg.raport02;\n\nvar require = global.get('require');\nvar xl = require('exceljs');\nvar workbook = new xl.Workbook();\n\nworkbook.creator = 'NodeRed exceljs';\nworkbook.lastModifiedBy = 'NodeRed exceljs';\nworkbook.created = new Date();\nworkbook.modified = new Date();\nworkbook.lastPrinted = new Date();\n\n// create a sheet with the first row and column frozen\nvar worksheet = workbook.addWorksheet(msg.arkusz1, {views:[{state: 'frozen', ySplit:1}]});\n\n\n\nworksheet.getColumn(1).width =20;\nworksheet.getColumn(2).width =60;\nworksheet.getColumn(3).width =25;\nworksheet.getColumn(4).width =12;\nworksheet.getColumn(5).width =35;\nworksheet.getColumn(6).width =20;\nworksheet.getColumn(7).width =15;\nworksheet.getColumn(8).width =20;\nworksheet.getColumn(9).width =15;\nworksheet.getColumn(10).width =15;\nworksheet.getColumn(11).width =15;\nworksheet.getColumn(12).width =20;\nworksheet.getColumn(13).width =15;\n\n// Nazwy kolumn\nvar columns = [];\nvar col = Object.keys(msg.raport02[0]);\n\nfor(var c in col)\n{\n columns.push({\"name\": col[c], \"filterButton\": true});\n}\n\n\n\n\n\nvar table={\n name: 'Raport_inwentury_Wew',\n ref: 'A1',\n headerRow: true,\n totalsRow: false,\n style: {\n theme: 'TableStyleMedium3',\n showRowStripes: true,\n },\n columns:columns,\n rows: [],\n};\n\n\nfor(var r in msg.raport02)\n{\n table.rows.push(Object.values(msg.raport02[r]));\n}\n\n\n//worksheet.autoFilter = 'A1:Z1';\n\nif(typeof msg.raport02!== undefined && msg.raport02 !== null && msg.raport02.length>0)\n worksheet.addTable(table);\n\n\n/////////////////////////////////////////////////////\nvar worksheet2 = workbook.addWorksheet(msg.arkusz2, {views:[{state: 'frozen', ySplit:1}]});\n\nworksheet2.getColumn(1).width =50;\nworksheet2.getColumn(2).width =60;\nworksheet2.getColumn(3).width =25;\n\nvar columns2 = [];\nvar col2 = Object.keys(msg.raport01[0]);\n\nfor(var c2 in col2)\n{\n columns2.push({\"name\": col2[c2], \"filterButton\": true});\n}\n\nvar table2={\n name: 'Raport2',\n ref: 'A1',\n headerRow: true,\n totalsRow: false,\n style: {\n theme: 'TableStyleMedium3',\n showRowStripes: true,\n },\n columns:columns2,\n rows: [],\n};\n\nfor(var r2 in msg.raport01)\n{\n table2.rows.push(Object.values(msg.raport01[r2]));\n}\n\n if(typeof msg.raport01!== undefined && msg.raport01 !== null && msg.raport01.length>0)\n worksheet2.addTable(table2);\n\n\n\n\n\n/////////////////////////////////////////////////////\nvar worksheet3 = workbook.addWorksheet(msg.arkusz3, {views:[{state: 'frozen', ySplit:1}]});\n\nworksheet3.getColumn(1).width =20;\nworksheet3.getColumn(2).width =20;\nworksheet3.getColumn(3).width =75;\nworksheet3.getColumn(4).width =85;\nworksheet3.getColumn(5).width =25;\nworksheet3.getColumn(6).width =25;\nworksheet3.getColumn(7).width =15;\n\nvar columns3 = [];\nvar col3 = Object.keys(msg.raport03[0]);\n\nfor(var c3 in col3)\n{\n columns3.push({\"name\": col3[c3], \"filterButton\": true});\n}\n\n\n\n\n\nvar table3={\n name: 'Raport3',\n ref: 'A1',\n headerRow: true,\n totalsRow: false,\n style: {\n theme: 'TableStyleMedium3',\n showRowStripes: true,\n },\n columns:columns3,\n rows: [],\n};\n\n\n\n\nfor(var r3 in msg.raport03)\n{\n table3.rows.push(Object.values(msg.raport03[r3]));\n}\n\n\n\n\n\nif(typeof msg.raport03 !== undefined && msg.raport03 !== null && msg.raport03.length>0)\n worksheet3.addTable(table3);\n\n\n////////////////////////////\n//////////////////////////\n/////////////////////////////\n\nvar worksheet4 = workbook.addWorksheet(msg.arkusz4, {views:[{state: 'frozen', ySplit:1}]});\n\nworksheet4.getColumn(1).width =20;\nworksheet4.getColumn(2).width =20;\nworksheet4.getColumn(3).width =75;\nworksheet4.getColumn(4).width =85;\nworksheet4.getColumn(5).width =25;\nworksheet4.getColumn(6).width =25;\nworksheet4.getColumn(7).width =15;\n\nvar columns4 = [];\nvar col4 = Object.keys(msg.raport04[0]);\n\nfor(var c4 in col4)\n{\n columns4.push({\"name\": col4[c4], \"filterButton\": true});\n}\n\n\n\n\n\nvar table4={\n name: 'Raport4',\n ref: 'A1',\n headerRow: true,\n totalsRow: false,\n style: {\n theme: 'TableStyleMedium3',\n showRowStripes: true,\n },\n columns:columns4,\n rows: [],\n};\n\n\n\n\nfor(var r4 in msg.raport04)\n{\n table4.rows.push(Object.values(msg.raport04[r4]));\n}\n\n\n\n\n\nif(typeof msg.raport04 !== undefined && msg.raport04 !== null && msg.raport04.length>0)\n worksheet4.addTable(table4);\n\n\n\n////////////\n\n////////////////////////////\n//////////////////////////\n/////////////////////////////\n\nvar worksheet5 = workbook.addWorksheet(msg.arkusz5, {views:[{state: 'frozen', ySplit:1}]});\n\nworksheet5.getColumn(1).width =20;\nworksheet5.getColumn(2).width =20;\nworksheet5.getColumn(3).width =75;\nworksheet5.getColumn(4).width =85;\nworksheet5.getColumn(5).width =25;\nworksheet5.getColumn(6).width =25;\nworksheet5.getColumn(7).width =15;\n\nvar columns5 = [];\nvar col5 = Object.keys(msg.raport05[0]);\n\nfor(var c5 in col5)\n{\n columns5.push({\"name\": col5[c5], \"filterButton\": true});\n}\n\n\n\n\n\nvar table5={\n name: 'Raport5',\n ref: 'A1',\n headerRow: true,\n totalsRow: false,\n style: {\n theme: 'TableStyleMedium3',\n showRowStripes: true,\n },\n columns:columns5,\n rows: [],\n};\n\n\n\n\nfor(var r5 in msg.raport05)\n{\n table5.rows.push(Object.values(msg.raport05[r5]));\n \n \n}\n\n\n\n\n\nif(typeof msg.raport05 !== undefined && msg.raport05 !== null && msg.raport05.length>0)\n worksheet5.addTable(table5);\n\n\n \n\nvar worksheet6 = workbook.addWorksheet(msg.arkusz6, {views:[{state: 'frozen', ySplit:1}]});\n\nworksheet5.getColumn(1).width =20;\nworksheet5.getColumn(2).width =20;\nworksheet5.getColumn(3).width =75;\nworksheet5.getColumn(4).width =85;\nworksheet5.getColumn(5).width =25;\nworksheet5.getColumn(6).width =25;\nworksheet5.getColumn(7).width =15;\n\nvar columns6 = [];\nvar col6 = Object.keys(msg.raport06[0]);\n\nfor(var c6 in col6)\n{\n columns6.push({\"name\": col6[c6], \"filterButton\": true});\n}\n\n\n\n\n\nvar table6={\n name: 'Raport6',\n ref: 'A1',\n headerRow: true,\n totalsRow: false,\n style: {\n theme: 'TableStyleMedium3',\n showRowStripes: true,\n },\n columns:columns6,\n rows: [],\n};\n\n\n\n\nfor(var r6 in msg.raport06)\n{\n table6.rows.push(Object.values(msg.raport06[r6]));\n \n \n}\n\n\n\n\n\nif(typeof msg.raport06 !== undefined && msg.raport06 !== null && msg.raport06.length>0)\n worksheet6.addTable(table6);\n\n\n\nvar worksheet7 = workbook.addWorksheet(msg.arkusz7, {views:[{state: 'frozen', ySplit:1}]});\n\nworksheet5.getColumn(1).width =20;\nworksheet5.getColumn(2).width =20;\nworksheet5.getColumn(3).width =75;\nworksheet5.getColumn(4).width =85;\nworksheet5.getColumn(5).width =25;\nworksheet5.getColumn(6).width =25;\nworksheet5.getColumn(7).width =15;\n\nvar columns7 = [];\nvar col7 = Object.keys(msg.raport07[0]);\n\nfor(var c7 in col7)\n{\n columns7.push({\"name\": col7[c7], \"filterButton\": true});\n}\n\n\n\n\n\nvar table7={\n name: 'Raport7',\n ref: 'A1',\n headerRow: true,\n totalsRow: false,\n style: {\n theme: 'TableStyleMedium3',\n showRowStripes: true,\n },\n columns:columns7,\n rows: [],\n};\n\n\n\n\nfor(var r7 in msg.raport07)\n{\n table7.rows.push(Object.values(msg.raport07[r7]));\n \n \n}\n\n\n\n\n\nif(typeof msg.raport07 !== undefined && msg.raport07 !== null && msg.raport07.length>0)\n worksheet7.addTable(table7);\n\n\n\n\n\n\nworkbook.xlsx.writeBuffer()\n .then(function(buffer) {\n msg.excel=buffer;\n node.send(msg);\n});\n\n",
        "outputs": 1,
        "timeout": "",
        "noerr": 3,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 885,
        "y": 280,
        "wires": [
            [
                "7549c41c.03690c"
            ]
        ],
        "l": false
    }
]

```

ADMIN EDIT: Wrap flows in triple backticks to make it importable

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 July 2025 08:05 UTC](https://discourse.nodered.org/t/problem-to-var-require-global-get-require-3-scheet-to-1-xlsx/98195/2 "2025-07-18T08:05:53Z")

</div>

Hi, firstly your flow was not correctly formatted for the forum so I corrected it for you

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

* * *

Next, I moved this thread to #General since you are not #Developing Nodes

* * *

Lastly, `require` is NOT really recommended or even necessary. I would use the `Setup` tab and add your npm module in there. See the below article for how to:

> **[Use any npm module in Node-RED • FlowFuse](https://flowfuse.com/blog/2023/06/import-modules/)**
>
> Node-RED has an incredibly rich resource of integrations available, but sometimes you need that little extra. This shows you how.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 July 2025 08:18 UTC](https://discourse.nodered.org/t/problem-to-var-require-global-get-require-3-scheet-to-1-xlsx/98195/3 "2025-07-18T08:18:00Z")

</div>

> [@Steve-Mcl](#):
>
> Lastly, `require` is really recommended or even necessary

I think there is a 'not' missing there.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [16 September 2025 08:18 UTC](https://discourse.nodered.org/t/problem-to-var-require-global-get-require-3-scheet-to-1-xlsx/98195/4 "2025-09-16T08:18:59Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
