我们如何将GRIDVIEW的数据导出到microsoft EXCEL sheet`中 [英] How can we export the data of GRIDVIEW in to microsoft EXCEL sheet`

查看:96
本文介绍了我们如何将GRIDVIEW的数据导出到microsoft EXCEL sheet`中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好;



我使用的是ASP.Net 4.0;



我们如何出口或将Gridview中显示的数据转换为Microsoft Office EXCEL表。



先谢谢..

解决方案

< blockquote>您好,



请尝试以下代码



 Response.Clear() ; 
Response.Charset =;
Response.ContentType =application / vnd.ms-excel;
Response.AppendHeader(content-disposition,attachment; filename = ExportData.xls);
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
GridView gv = new GridView();
gv.DataSource = dt; //在此分配您分配给网格的数据表。
gv.DataBind();
gv.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();


CodeProject 存档中快速搜索后:

- 如何将GridView导出到Excel,渲染单元格,添加艺术字和填充自定义模板 [ ^ ]

- 使用C#将Gridview和Datareader中的大数据导出到Excel文件[ ^ ]

- 将DataGrid导出到Excel,Word和文本文件 [ ^ ]



还有很多很多例子es ...


查看此链接

将GridView导出到Excel [ ^ ]

Hello;

I am using ASP.Net 4.0;

How can we export or convert the data which displayed in Gridview in to Microsoft office EXCEL sheet.

Thanks in Advance..

解决方案

Hi,

Try following code

Response.Clear();
Response.Charset = "";
Response.ContentType = "application/vnd.ms-excel";
Response.AppendHeader("content-disposition", "attachment; filename=ExportData.xls");
System.IO.StringWriter sw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw);
GridView gv = new GridView();
gv.DataSource = dt; // assign your datatable here that you assign to grid.
gv.DataBind();
gv.RenderControl(hw);
Response.Write(sw.ToString());
Response.End();


After a very quick search in the CodeProject archive:
- How to export GridView to Excel, render cells, add WordArt, and fill a custom template[^]
- Export large data from Gridview and Datareader to an Excel file using C#[^]
- Exporting DataGrid to Excel, Word and Text Files[^]

And there are many, many more examples...


check this link
Export GridView to Excel[^]


这篇关于我们如何将GRIDVIEW的数据导出到microsoft EXCEL sheet`中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆