Introduction: The first few days in the Web project to do the need to export the data on the page to Excel but sometimes garbled (there is de time does not appear very strange) The original code is this: HttpContext.Current.Response.Clear (); HttpContext.Current.Response.AddHeader ("Content-disposition", "Attachment;filename=filename.xls"); HttpContext.Current.Response.Charset = "GB2312"; HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding ("GB2312");//. unicode;//. utf8;//HttpContext.Current.Response.ContentType = "xls"; "Application/vnd.xls"; System.IO.StringWriter stringwrite = new System.IO.StringWriter (); System.Web.UI.HtmlTextWriter htmlwrite = new HtmlTextWriter (Stringwrite); MyGridView. RenderControl (HTW); HttpContext.Current.Response.Write (SW. ToString ()); HttpContext.Current.Response.End (); How do I fix it? Modify the following code to solve the problem of HttpContext.Current.Response.ClearContent (); HttpContext.Current.Response.Write (" "); HttpContext.Current.Response.AddHeader ("Content-disposition", "attachment; Filename=myexcelfile.xls "); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding ("GB2312"); HttpContext.Current.Response.ContentType = "Application/excel"; System.IO.StringWriter SW = new System.IO.StringWriter (); System.Web.UI.HtmlTextWriter htw = new System.Web.UI.HtmlTextWriter (SW); MyGridView. RenderControl (HTW); HttpContext.Current.Response.Write (SW. ToString ()); HttpContext.Current.Response.End (); a careful comparison is HttpContext.Current.Response.Write (" "); The function of this sentence (the function of this sentence is to declare that the page is encoded using gb2312) is HttpContext.Current.Response.Charset = "GB2312"; I thought that was a good thing to do, or to use it. Compare Insurance