Sometimes, we want to read Excel file using Node.js and JavaScript
In this article, we’ll look at how to read Excel file using Node.js and JavaScript.
How to read Excel file using Node.js and JavaScript?
To read Excel file using Node.js and JavaScript, we use the node-xlsx
package.
To install it, we run
npm install node-xlsx --save
Then we use it by writing
const xlsx = require("node-xlsx");
const obj = xlsx.parse(__dirname + "/myFile.xlsx");
to parse a file at the path with xlsx.parse
.
We can parse a buffer with
const obj = xlsx.parse(fs.readFileSync(__dirname + "/myFile.xlsx"));
We read the file with readFileSync
and then parse the returned buffer.
Conclusion
To read Excel file using Node.js and JavaScript, we use the node-xlsx
package.