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

        }
    }
4
  • What have u tried so far? Commented Sep 6, 2018 at 6:25
  • Take a look at:stackoverflow.com/a/1746924/7124761 Commented Sep 6, 2018 at 6:25
  • Check this question please,; it is not exactly you want probably but you modify according your requirements : stackoverflow.com/questions/18182029/… Commented Sep 6, 2018 at 6: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? Commented Sep 7, 2018 at 7:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.