The example above assumes that the datatable contains the same column names with the excel table.
You can download the library from http://closedxml.codeplex.com/http://closedxml.codeplex.com/
if (table.Rows.Count > 0) { wstable.InsertRowsBelow(table.Rows.Count - 1); var excelrow = wstable.DataRange.FirstRow(); int loop = 1; foreach (DataRow row in table.Rows) { foreach (DataColumn column in table.Columns) { excelrow.Field(column.ColumnName).Value = row[column.ColumnName]; } loop = loop + 1; excelrow = wstable.DataRange.Row(loop); } }The example above assumes that the datatable contains the same column names with the excel table.
No comments:
Post a Comment