/// <summary> /// 导出EXCEL方法 /// </summary> /// <param name="page"></param> /// <param name="fileName"></param> /// <param name="html"></param> protected void ExportDsToXls(Page page, string fileName, string html) { System.IO.StringWriter tw = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw); Response.Clear(); Response.Charset = "gb2312"; Response.ContentType = "application/vnd.ms-excel"; Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312"); Response.AppendHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName) + ".xls"); Response.Write("<html><head><META http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\"></head><body>"); Response.Write(html); Response.Write(tw.ToString()); Response.Write("</body></html>"); Response.End(); hw.Close(); hw.Flush(); tw.Close(); tw.Flush(); }