GridVew数据导出到Wrod、Excl

  刚开是我用来一种方法是本地是可以导出来的, 但是到了服务器就不可以了。代码我们有保留,现在是我修改后的。

 

 

 ///

/// 导出GridVew数据信息 /// /// 类型 /// 名称.后缀 /// 控件名称 public static void Export(string FileType, string FileName, GridView gv) { System.Web.HttpContext.Current.Response.Charset = "GB2312"; System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF7; System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString()); System.Web.HttpContext.Current.Response.ContentType = FileType; //this.EnableViewState = false; StringWriter tw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(tw); gv.RenderControl(hw); System.Web.HttpContext.Current.Response.Write(tw.ToString()); System.Web.HttpContext.Current.Response.End(); }



西安河豚软件科技有限公司

你可能感兴趣的:(GridVew数据导出到Wrod、Excl)