简体   繁体   中英

Convert JSON to XLSX and download it in NodeJS

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');

To get that work use npm i node-json-xlsx

https://www.npmjs.com/package/node-json-xlsx

you can use also npm i xlsx

find more at : https://www.npmjs.com/package/xlsx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM