If you want to access data from an excel file, there are two methods to do so.
The first method involves using the xlsx package. To begin, navigate to your project folder and run the command 'npm i xlsx' in the terminal to install the necessary packages.
var XLSX = require('xlsx');
var UserCred = XLSX.readFile('ExcelFile/UserLogin.xlsx');
var UserLoginWorksheet= UserCred.Sheets['Sheet1'];
var BaseUrl=UserLoginWorksheet['B1'].v;
console.log(BaseUrl);
In this code snippet, 'BaseUrl' stores the value located at column B1 in the excel file.
The second method utilizes the exceljs package. Similarly, go to your project folder and run 'npm i excel' in the terminal to install the required packages.
var Excel = require("exceljs");
var filePath = 'ExcelFiles/StaffDetails.xlsx';
var workbook = new Excel.Workbook();
await workbook.xlsx.readFile(filePath).then(function () {
worksheet = workbook.getWorksheet("Sheet1"); //Use sheetName in getWorksheet function
let cellValue1 = worksheet.getRow(1).getCell(1).value;
console.log(cellValue1+"4");
})
let cellValue2 = worksheet.getRow(2).getCell(2).value;
Here, cellvalue1 represents the value of cell A1, while cellvalue2 represents the value of cell B2 in the excel file.