//摘自http://www.dotnetsky.net/netsave/ShowTopic-77067.html //
try{
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
Response.ContentEncoding=System.Text.Encoding.GetEncoding("UTF-8");//设置输出流为简体中文Response.AppendHeader("Content-Disposition","attachment;filename=test.xls"); Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 this.EnableViewState = false;
CultureInfo myCItrad = new CultureInfo("ZH-CN",true); HtmlGenericControl div=new HtmlGenericControl(); System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); div.InnerHtml = oStringWriter.ToString(); System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter); // 下载页面显示的
DataGrid1.RenderControl(oHtmlTextWriter); // LZ 注意此处DataGrid1div.InnerHtml =oStringWriter.ToString();
Response.Write(div.InnerText); Response.End();
}
catch( Exception ex)
{MsgBox("",ex.Message);}