protected void ExportToExcel(object sender, EventArgs e) { Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=VIPadmVisitors.xls"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-excel"; Response.ContentEncoding = Encoding.Unicode; Response.BinaryWrite(Encoding.Unicode.GetPreamble()); using (StringWriter sw = new StringWriter()) { HtmlTextWriter hw = new HtmlTextWriter(sw); //To Export all pages gvVisitedVisitors.AllowPaging = false; //this.BindGrid(); gvVisitedVisitors.Columns[1].Visible = false; gvVisitedVisitors.RenderControl(hw); //style to format numbers to string //string style = @"<style> .textmode { mso-number-format:\@; } </style>"; string style = @"<style> td { mso-number-format:\@;} </style>"; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } }
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)