public static void ExportExcel(string FileName, StringBuilder table) { HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流的字符集 HttpContext.Current.Response.Charset = "gb2312"; HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName)); HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; StringWriter sw = new StringWriter(table); //HtmlTextWriter htw = new HtmlTextWriter(sw); //Page page = new Page(); //page.EnableEventValidation = false; //page.DesignerInitialize(); //page.RenderControl(htw); HttpContext.Current.Response.Write("" + sw.ToString()); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); }