使用ClosedXML附加到excel文件 [英] Append to excel file with ClosedXML

查看:691
本文介绍了使用ClosedXML附加到excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将新数据附加到使用ClosedXML创建的现有excel文件。



如何使用ClosedXML附加到excel文件?
如何获取最后一条记录的行号并附加到其他位置?还有还有什么其他的?



谢谢!

解决方案

打开现有的工作簿,然后使用 Last * Used 方法:

$ b $新的XLWorkbook(C:\existing_excel_file.xlsx);
IXLWorkSheet Worksheet = Workbook.Worksheet(要使用的工作表的名称或索引);

int NumberOfLastRow = Worksheet.LastRowUsed()。RowNumber;
IXLCell CellForNewData = Worksheet.Cell(NumberOfLastRow + 1,1);

然后根据您的数据使用以下之一:

  CellForNewData.SetValue(data); 
CellForNewData.InsertData(data);
CellForNewData.InsertTable(datatable);

有关更多信息,请参阅文档


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(data);
CellForNewData.InsertTable(datatable);

For more information see the documentation under "Inserting Data/Tables".

这篇关于使用ClosedXML附加到excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆