Reputation: 189
I am trying to process an excel sheet using exceljs but need to insert data into the database while processing each row and entering information into the database. At the end of processing each row I need to insert the value as success/failure and return it back as a excel sheet with failures. I need to process these rows one after the other.
Upvotes: 2
Views: 18282
Reputation: 1248
You can take a look at ExcelJs documentation, which clearly mentions the steps to iterate the rows in a worksheet.
The worksheet.eachRow()
function which allows you to do this.
// Iterate over all rows that have values in a worksheet
worksheet.eachRow(function(row, rowNumber) {
console.log('Row ' + rowNumber + ' = ' + JSON.stringify(row.values));
//Do whatever you want to do with this row like inserting in db, etc
});
// Iterate over all rows (including empty rows) in a worksheet
worksheet.eachRow({ includeEmpty: true }, function(row, rowNumber) {
console.log('Row ' + rowNumber + ' = ' + JSON.stringify(row.values));
//Do whatever you want to do with this row like inserting in db, etc
});
Upvotes: 11