Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", string.Format("attachment;filename={0}.xls", "" + Result + "")); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); string style = string.Empty; //To Export all pages GridView1.AllowPaging = false; GridView1.HeaderRow.BackColor = Color.White; foreach (TableCell cell in GridView1.HeaderRow.Cells) { cell.BackColor = GridView1.HeaderStyle.BackColor; } foreach (GridViewRow row in GridView1.Rows) { row.BackColor = Color.White; foreach (TableCell cell in row.Cells) { string value = cell.Text; string text = value[0].ToString(); if (text == "0") { cell.Text = cell.Text; } if (row.RowIndex % 2 == 0) { cell.BackColor = GridView1.AlternatingRowStyle.BackColor; } else { cell.BackColor = GridView1.RowStyle.BackColor; } cell.CssClass = "textmode"; //cell.Style.Add("style", "mso-number-format:\\@"); } } GridView1.RenderControl(hw); //style to format numbers to 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)