I have 7 DataTables (of different number of rows, columns) in my asp.net page (C#). I am displaying the data on my page using GridViews. There is a requirement of exporting these dataTables to an excel file in such a way that I need the data of first 5 DataTables on first sheet, data of 6th DataTable on 2nd sheet and data of 7th DataTable on 3rd sheet of the same excel file.
I searched on google a lot but no luck ! Please help me with this.
UPDATE: I implemented the solution using excel interop. The first sheet (having 5 datatables and graphs thereof) is loading fine. But second and third sheets are taking too much time (4000-5000 rows of data and 50 columns approx in each sheet) in loading.
Is there any way to load them fast?
I am using the following code:
Worksheet xlWorksheet2 = null;
//Create Excel Sheets
xlSheets = ExcelApp.Sheets;
xlWorksheet2 = (Worksheet)xlSheets.Add(xlSheets[2], Type.Missing, Type.Missing, Type.Missing);
xlWorksheet2.Name = "Dump-1";
table = Dump1();
for (int j = 1; j < table.Columns.Count + 1; j++)
{
ExcelApp.Cells[1, j] = table.Columns[j - 1].ColumnName;
}
// Storing Each row and column value to excel sheet
for (k = 0; k < table.Rows.Count; k++)
{
for (int l = 0; l < table.Columns.Count; l++)
{
ExcelApp.Cells[k + 2, l + 1] = table.Rows[k].ItemArray[l].ToString();
}
}