GridView GridView1 = new GridView(); GridView1.DataSource = ((DataTable)Session["EXECUTIVE_ACT_RPT"]); GridView1.DataBind(); Response.Clear(); Response.Buffer = true; Response.AddHeader("Content-Disposition", "attachment; filename=abc.xlsx"); //Choose one of these: as the contentType //Excel 2003 : "application/vnd.ms-excel" //Excel 2007 : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; System.IO.StringWriter writer = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter html = new System.Web.UI.HtmlTextWriter(writer); GridView1.RenderControl(html); Response.Write(writer); Response.End();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)