how do i append existing excel files in nodejs using exceljs?

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

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top