-1

How can I append to the last open row of an already existing Excel file in NodeJS using ExcelJS?.

Tackten
  • 47
  • 1
  • 9

1 Answers1

1

You can use lastRow Attribute to get the last row of the current sheet. Then increment that value and add new records to the new Row.

let nameFileExcel = 'YourExcelFile.xlsx'
var workbook = new exceljs.Workbook();
workbook.xlsx.readFile(nameFileExcel)
.then(function()  {
    var worksheet = workbook.getWorksheet(1);
    var lastRow = worksheet.lastRow;
    var getRowInsert = worksheet.getRow(++(lastRow.number));
    getRowInsert.getCell('A').value = 'New Value';
    getRowInsert.commit();
    return workbook.xlsx.writeFile(nameFileExcel);
});

Reference: Click Here

Harshana
  • 5,151
  • 1
  • 17
  • 27