To parse XLSX with Node and create JSON, we use the xlsx
module.
For instance, we write
const XLSX = require("xlsx");
const workbook = XLSX.readFile("master.xlsx");
const sheetNameLlist = workbook.SheetNames;
console.log(XLSX.utils.sheet_to_json(workbook.Sheets[sheetNameLlist[0]]));
to call readFile
to read master.xlsx.
And we get the sheets names from SheetNames
.
Next, we call sheet_to_json
with the sheet we get from workbook.Sheets[sheetNameLlist[0]]
to return the sheet data as JSON.