日期:2014-05-18 浏览次数:20646 次
public static void ToExcelOrWord(Control gvName,string contentType,string fileName)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Charset="GB2312";
HttpContext.Current.Response.Buffer=true;
HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+HttpContext.Current.Server.UrlEncode(fileName));
HttpContext.Current.Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
HttpContext.Current.Response.ContentType=contentType;
gvName.Page.EnableViewState=false;
System.Globalization.CultureInfo myCItrad=new System.Globalization.CultureInfo("ZH-CN",true);
StringWriter stringWriter=new StringWriter(myCItrad);
HtmlTextWriter htmlWriter=new HtmlTextWriter(stringWriter);
gvName.RenderControl(htmlWriter);
HttpContext.Current.Response.Write(stringWriter.ToString());
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}