Convert JSON to XLSX and download it in NodeJS

Issue

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

Solution

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

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

Answered By – Hisham Shami

Answer Checked By – Senaida (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.