dataset ds=new dataset(); GridView GridView1 = new GridView(); GridView1.AllowPaging = false; GridView1.DataSource = ds; GridView1.DataBind(); Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=DataTable.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); for (int i = 0; i < GridView1.Rows.Count; i++) { GridView1.Rows[i].Attributes.Add("class", "textmode"); } GridView1.RenderControl(hw); string style = @"<style> .textmode { mso-number-format:\@; } </style>"; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)