将gridview数据导出到ecxel的代码
问题描述:
需要按钮代码将gridview数据导出到ecxel,pls帮助
need button code to export gridview data to ecxel,pls help
答
使用以下代码
use below code
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Buffer = true;
Response.ContentType = "application/vnd.xls";
Response.Charset = "";
EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
ClearControls(grd);
GridView1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
http://www.codeproject.com /KB/aspnet/GridViewFaqs.aspx#heading0010 [ ^ ]应该会有所帮助.
http://www.codeproject.com/KB/aspnet/GridViewFaqs.aspx#heading0010[^] should help.
搜索引擎是查找有关此类问题的详细信息的最佳媒体之一.
必应搜索结果
Search Engines are one of the best media to find details around this kind of Questions.
Google Search Result
Bing Search Result