In this blog post, you will learn how to read Excel file using JavaScript. exceljs – JavaScript Excel Library reads, manipulates and writes spreadsheet data and styles to XLSX and JSON.
We have used Apache POI, Fillo, JXL, and pyxll Excel Java & Python libraries for automation testing services. However, Reading and manipulating Excel file in JavaScript is very interesting.
Installation
You can install exceljs Excel Workbook Manager with the below npm install command.
`npm install exceljs`
Code
//Read a file var workbook = new Excel.Workbook(); workbook.xlsx.readFile("data/Sample.xlsx").then(function () { //Get sheet by Name var worksheet=workbook.getWorksheet('Sheet1'); //Get Lastrow var row = worksheet.lastRow //Update a cell row.getCell(1).value = 5; row.commit(); //Save the workbook return workbook.xlsx.writeFile("data/Sample.xlsx"); });
You can also read and write CSV file. Refer: Reading CSV and Writing CSV
Comments(0)