#region 处理输出类型 switch (fileType) { case FileType.Excel: page.Response.Charset = "GB2312"; page.Response.AppendHeader("Content-Disposition", "attachment;filename=ExportFile.xls"); page.Response.ContentType = "application/ms-excel"; break; case FileType.Html: page.Response.Charset = "GB2312"; page.Response.AppendHeader("Content-Disposition", "attachment;filename=ExportFile.html"); page.Response.ContentType = "application/ms-html"; break; case FileType.Word: page.Response.Charset = "GB2312"; page.Response.AppendHeader("Content-Disposition", "attachment;filename=ExportFile.doc"); page.Response.ContentType = "application/ms-word"; break; default: page.Response.Charset = "GB2312"; page.Response.AppendHeader("Content-Disposition", "attachment;filename=ExportFile.xls"); page.Response.ContentType = "application/ms-excel"; break; } #endregion page.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); //设置输出流为简体中文 //this.EnableViewState = false; //System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true); System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); controlName.RenderControl(oHtmlTextWriter); page.Response.Write(oStringWriter.ToString()); page.Response.End(); }