gridview data export to excel in asp.net

前端 未结 7 1017
情歌与酒
情歌与酒 2020-12-15 11:25

i tried to transfer grid view data to excel .... But the output is a blank excel sheet.How to solve this problem?Is there any code to transfer grid view value to excel sheet

相关标签:
7条回答
  • 2020-12-15 12:16

    Instead of doing all these.. cant you use a simpler approach as shown below.

    Response.ClearContent();
                Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
                Response.ContentType = "application/excel";
                System.IO.StringWriter sw = new System.IO.StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                gv.RenderControl(htw);
                Response.Write(sw.ToString());
                Response.End();
    

    You can get the entire walkthrough here

    0 讨论(0)
提交回复
热议问题