c# 将DataGrid中的项导出为Excel

this.DataGrid1.AllowPaging=false;
 Bind(DataGrid1,"select * from [work]");
  Response.Clear();   
  Response.Charset="utf-8";    //输出
  string Title = this.Title.Text;
  Response.AppendHeader("Content-Disposition","attachment;filename="+System.Web.HttpUtility.UrlEncode(Title)+".xls");    
  Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");   //设置输出编码
  System.IO.StringWriter   osw=new System.IO.StringWriter();//new   System.IO.StringWriter(myinfo);   
  System.Web.UI.HtmlTextWriter   ohtw=new   System.Web.UI.HtmlTextWriter(osw);   
  DataGrid1.RenderControl(ohtw);  
  Response.Write(osw);   
  Response.End();
posted @ 2009-07-15 17:10  悟〈--觉  阅读(6812)  评论(0编辑  收藏  举报