Categories
JavaScript Answers

How to parse XLSX with Node and create JSON?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.