/// <summary> /// 导出Excel /// </summary> /// <param name="gv">HHGridView</param> /// <param name="title">表头</param> public static void HHGridViewToExcel(HHGridView gv, string title) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.Charset = "GB2312"; HttpContext.Current.Response.Write("<meta http-equiv=Content-Type content=text/html;charset=GB2312>"); HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName); HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312"); HttpContext.Current.Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlTextWriter = new System.Web.UI.HtmlTextWriter(stringWriter); gv.RenderControl(htmlTextWriter); if (!string.IsNullOrEmpty(title)) { HttpContext.Current.Response.Write("<b><center><font size=3 face=Verdana>" + title + "</font></center></b>"); } HttpContext.Current.Response.Output.Write(stringWriter.ToString()); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); }
/// <summary> /// 导出Excel /// </summary> /// <param name="gv">HHGridView</param> public static void HHGridViewToExcel(HHGridView gv) { HHGridViewToExcel(gv, string.Empty); }