我想将数据从我的 excel 表导出到数据表,但不知道如何将数据放入数据表。有人可以帮我吗?
我的代码是:
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(userSelectedFilePath2);
Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
Excel.Range xlRange = xlWorksheet.UsedRange;
DataTable excelTb = new DataTable();
for (int i = 0; i <= xlRange.Rows.Count - 1; i++)
{
for (int j = 1; j <= xlRange.Columns.Count; j++)
{
excelTb.Columns.Add(xlRange.Cells[0,j].Value2.ToString());
foreach (DataRow extb in excelTb.Rows)
{
DataRow newDataRow = excelTb.NewRow();
// Here should be something to put data in DataTable
}
}
}