public void ExporttoExcel(GridView gv) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Customers.xls")); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; StringWriter sw = new StringWriter(); HtmlTextWriter htw = new HtmlTextWriter(sw); gv.AllowPaging = false; gv.DataBind(); gv.HeaderRow.Style.Add("background-color", "#FFFFFF"); gv.RenderControl(htw); HttpContext.Current.Response.Write(sw.ToString()); HttpContext.Current.Response.End(); } protected void btnExcel_Click(object sender, ImageClickEventArgs e) { at.ExporttoExcel(gvDailyAttendenceReport); } protected void btnShow_Click(object sender, EventArgs e) { showDailyAttendance();//function to bindgridview (datatable as datasource) }
Quote: C# Response.Charset = ""; Response.ContentEncoding = System.Text.Encoding.Default;
Response.Charset = ""; Response.ContentEncoding = System.Text.Encoding.Default;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)