Reputation: 169
I am trying to convert JSON to XLSX in nodejs download that XLSX to the client browser. I used XLSX npm module to convert json to XLSX it is converting the JSON to Workbook, but I cannot download that file.
const arr = [
{ name: 'Moran', role: 'back' },
{ name: 'Alain', role: 'front' },
{ name: 'Tony', role: 'back' },
{ name: 'Mike', role: 'back' },
{ name: 'Abo', role: 'back' },
{ name: 'Toni', role: 'back' },
]
const fileName = 'test.xlsx';
const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(arr);
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'test');
Upvotes: 3
Views: 13238
Reputation: 778
This should be the correct way
const ws = XLSX.utils.json_to_sheet(theData);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
const filename="myfilename.xlsx";
XLSX.writeFile(wb, filename);
Upvotes: 3
Reputation: 211
you can use also npm i xlsx
find more at : https://www.npmjs.com/package/xlsx
Upvotes: 2
Reputation: 26
To get that work
use npm i node-json-xlsx
https://www.npmjs.com/package/node-json-xlsx
Upvotes: 1