I am working npm xlsx and want to create a xlsx file on my local device from the json output. I have gotten npm xlsx to load and I am using an example I found online to test. I get nothing when I run the function.
let XLSX = global.get('xlsx')
/* original data */
var data = [
{ "name": "John", "city": "Seattle" },
{ "name": "Mike", "city": "Los Angeles" },
{ "name": "Zach", "city": "New York" }
];
/* this line is only needed if you are not adding a script tag reference */
if (typeof XLSX == 'undefined') XLSX = require('xlsx');
/* make the worksheet */
var ws = XLSX.utils.json_to_sheet(data);
/* add to workbook */
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "People");
/* write workbook */
XLSX.write(wb, { bookType: 'xlsx', type: 'buffer' });
Here is the output from the global.get('xlsx')
see flow below. thanks
[{"id":"c0fe6321df5e43c0","type":"inject","z":"6aa33e2ddb33f623","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":220,"wires":[["bcba72236e7aca66"]]},{"id":"bcba72236e7aca66","type":"function","z":"6aa33e2ddb33f623","name":"function 1","func":"let XLSX = global.get('xlsx')\n\n/* original data */\nvar data = [\n { \"name\": \"John\", \"city\": \"Seattle\" },\n { \"name\": \"Mike\", \"city\": \"Los Angeles\" },\n { \"name\": \"Zach\", \"city\": \"New York\" }\n];\n\n/* this line is only needed if you are not adding a script tag reference */\nif (typeof XLSX == 'undefined') XLSX = require('xlsx');\n\n/* make the worksheet */\nvar ws = XLSX.utils.json_to_sheet(data);\n\n/* add to workbook */\nvar wb = XLSX.utils.book_new();\nXLSX.utils.book_append_sheet(wb, ws, \"People\");\n\n/* write workbook */\nXLSX.write(wb, { bookType: 'xlsx', type: 'buffer' });\n\n\n\n","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"xlsx","module":"xlsx"}],"x":260,"y":220,"wires":[["c29b1f5edf30cbb8"]]},{"id":"c29b1f5edf30cbb8","type":"debug","z":"6aa33e2ddb33f623","name":"debug 1","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":430,"y":220,"wires":[]}]