string fileName = "attachment;filename= ArchivalReportOn_" + DateTime.Now.ToString("dd-MM-yyyy-hh-mm-ss") + ".xls"; Response.Clear(); Response.AddHeader("content-disposition", fileName); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/ms-excel"; GridView gridview1 = new GridView(); gridview1.DataSource = dt; gridview1.HeaderStyle.CssClass = "gridHeader"; gridview1.HeaderStyle.BackColor = System.Drawing.Color.Red; gridview1.HeaderStyle.ForeColor = System.Drawing.Color.White; gridview1.DataBind(); System.IO.StringWriter stringWrite = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); gridview1.RenderControl(htmlWrite); string s_styleInfo = @"<style> td { mso-number-format:""" + "\\@" + @"""; }</style>"; string s_excel = stringWrite.ToString(); Response.Write(s_styleInfo + s_excel); Response.End();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)