1 protected void CopyToExcel() { 2 Response.Clear(); 3 Response.Buffer = true; 4 Response.Charset = "utf-8"; 5 Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("test", System.Text.Encoding.UTF8) + ".xls"); 6 Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); 7 Response.ContentType = "application/ms-excel"; 8 this.EnableViewState = false; 9 System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true); 10 System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); 11 System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); 12 13 this.rptResult.RenderControl(oHtmlTextWriter); 14 Response.Write(oStringWriter.ToString()); 15 Response.End(); 16 }