I want to export data from my excel tables to datatable but don't know how should i put the data to the DataTables. Can someone help me with it?
My code would be:
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
}
}
}