I need to append new data to existing excel file created with ClosedXML.
How can I append to an excel file using ClosedXML? How can I get the row number of the last record and append to that or is there something other?
Thanks!
Open the existing workbook and then use the Last*Used
methods:
XLWorkbook Workbook = new XLWorkbook(@"C:\existing_excel_file.xlsx");
IXLWorksheet Worksheet = Workbook.Worksheet("Name or index of the sheet to use");
int NumberOfLastRow = Worksheet.LastRowUsed().RowNumber();
IXLCell CellForNewData = Worksheet.Cell(NumberOfLastRow + 1, 1);
And then use one of the following depending on your data:
CellForNewData.SetValue(data);
CellForNewData.InsertData(data2);
CellForNewData.InsertTable(datatable);
For more information see the documentation under Inserting Data or Inserting Tables .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.