0

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();

        }
    }
DeepakVerma
  • 99
  • 10
  • What have u tried so far? – Prashant Pimpale Sep 06 '18 at 06:25
  • Take a look at:https://stackoverflow.com/a/1746924/7124761 – Prashant Pimpale Sep 06 '18 at 06:25
  • Check this question please,; it is not exactly you want probably but you modify according your requirements : https://stackoverflow.com/questions/18182029/how-to-export-datagridview-data-instantly-to-excel-on-button-click – nzrytmn Sep 06 '18 at 06:34
  • Thanks a lot Prashant Pimpale and nzrytmn... I implemented the solutions as given by you (using excel interop). The first sheet having datatables and graphs 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). Is there any way to load them fast? – DeepakVerma Sep 07 '18 at 07:59

0 Answers0