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();
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();