Sometimes, we want to read an Excel file using Node.js.
In this article, we’ll look at how to read an Excel file using Node.js.
How to read an Excel file using Node.js?
To read an Excel file using Node.js, we can use the node-xlsx
module.
To install it, we run
npm i node-xlsx
Then we can use it by writing
const xlsx = require('node-xlsx');
const obj1 = xlsx.parse(__dirname + '/myFile.xlsx');
const obj2 = xlsx.parse(fs.readFileSync(__dirname + '/myFile.xlsx'));
to call xlsx.parse
with the path of the Excel file and assign the returned object to obj1
.
Then we call xlsx.parse
with a buffer returned from reading the Excel file with readFileSync
and assign that to obj2
.
Conclusion
To read an Excel file using Node.js, we can use the node-xlsx
module.