Hi,
Well, you may insert rows (Cells.InsertRows()) and then put values into the cells accordingly in the ListObject/Table range.
Also, you may import even a datatable to paste into ListObject accordingly. See a sample code below:
Sample code:
//I open a file that contains a list object already.
Workbook workbook = new Workbook(“e:\test\MyListTable.xls”);
Worksheet worksheet = workbook.Worksheets[0];
DataSet ds = new DataSet();
System.Data.DataTable dt = new DataTable(“Table1”);
dt.Columns.Add(“Customer Identification Number”, typeof(string));
dt.Columns.Add(“Customer Name”, typeof(string));
dt.Columns.Add(“Description Text”, typeof(string));
for (int i = 1; i <= 20; i++)
{
System.Data.DataRow dr = dt.NewRow();
dr[“Customer Identification Number”] = i.ToString();
dr[“Customer Name”] = "Name " + i;
dr[“Description Text”] = "Description " + i;
dt.Rows.Add(dr);
}
ds.Tables.Add(dt);
worksheet.Cells.InsertRows(1, ds.Tables[0].Rows.Count);
bool exportFieldName = true;
if (exportFieldName)
{
//put true for the last parameter, doing so, it will first insert blank rows then paste data
worksheet.Cells.ImportDataTable(ds.Tables[0], true, 0, 0, true);
workbook.Worksheets[0].ListObjects[0].UpdateColumnName();
}
else
{
worksheet.Cells.ImportDataTable(ds.Tables[0], false, 1, 0, true);
}
workbook.Save(@“E:\test\output.xlsx”);
Thank you.