locked
Creating export messages RRS feed

  • Question

  • User279786496 posted

    How to create an export button to export data in excel format.

    I did a code for one table data, but when it comes to all the tables or view data from procedures how to do it?

    For eg : based on selection of the columns from frontend we will export the data.

    Thursday, July 20, 2017 5:27 PM

All replies

  • User-1716951449 posted

    https://blogs.msdn.microsoft.com/kenobonn/2014/11/09/httphandler-for-excel-file-download/

    Friday, July 21, 2017 1:33 AM
  • User279786496 posted

    I am looking for asp.net and C# code for the below logic.

    When I click on the button (load) I want to display start and end dates parameter which will select data from drop down list. and the validation must be end week is lesser than start week.

    and the data should be in this format  week1 January 2015

    once the user select start and end dates they will click on export to see the data in excel.

    Friday, July 21, 2017 2:40 PM
  • User1724605321 posted

    Hi ,

    When you show the table in page , you must get data from database(or files ..) , if you are using c# to get data , you may get a datatable  and bind the datatable  to control(for example, gridview) to show the table . It is not difficult to add dropdownlist to your page , and check the values according to selection of dropdownlist  . The main part is how to export records to excel  ,  please refer to below link for how to export DataTable to Excel :

    https://stackoverflow.com/questions/8207869/how-to-export-datatable-to-excel 

    Best Regards,

    Nan Yu

    Tuesday, July 25, 2017 6:15 AM
  • User-1865945774 posted

    Hello try this method.

          

    string attachment = "attachment; filename=test.xls";

                Response.ClearContent();

                Response.AddHeader("content-disposition", attachment);

                Response.ContentType ="application/ms-excel";

               StringWriter sw = new StringWriter();

               HtmlTextWriter htw = new HtmlTextWriter(sw);

                GridView1.RenderControl(htw);

               GridView2.RenderControl(htw);

                GridView3.RenderControl(htw);

                GridView4.RenderControl(htw);

                GridView5.RenderControl(htw);

                GridView6.RenderControl(htw);

                Response.Write(sw.ToString());

                Response.End();

           

    Wednesday, July 26, 2017 6:16 AM