如何在不导出gridview控件的情况下将gridview导出为ex​​cel [英] How to export gridview to excel without exporting gridview controls

查看:61
本文介绍了如何在不导出gridview控件的情况下将gridview导出为ex​​cel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将gridview导出到excel时,某些控件会在我尝试时导出(ieButton和Checkbox),如何删除/隐藏这些控件不会出现在我的Excel工作表中?



这是我用来将我的Gridview导出到excel的代码。

Response.Clear(); Response.AddHeader(content-disposition,attachment; filename = Untitled.xls); Response.Charset =; //如果你想要选项打开Excel文件而不保存,那么//注释掉下面的行// Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType =application / vnd.xls; System.IO.StringWriter stringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter); worklistGridView.RenderControl(的HTMLWriter);回复于(stringWriter.ToString()); Response.End();

When i export my gridview to excel, certain controls gets exported when i try to do so (i.e.Button and Checkbox), how can i remove/hide those controls from appearing in my excel sheet?

Here is the code that i am using to export my Gridview to excel.
Response.Clear(); Response.AddHeader("content-disposition", "attachment;filename=Untitled.xls"); Response.Charset = ""; // If you want the option to open the Excel file without saving then // comment out the line below // Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.xls"; System.IO.StringWriter stringWriter = new System.IO.StringWriter(); System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter); worklistGridView.RenderControl(htmlWriter); Response.Write(stringWriter.ToString()); Response.End();

推荐答案

您可以使用名为iTextSharp的开源库。有了这个,你可以导出你的gridview数据。
you can use open source library called iTextSharp. With this you can export your gridview data.


这是我发现的,它被认为是将GridView导出到Excel时的最佳实践,它就像一个魅力。 />
查看链接...

http://www.koders.com/csharp/fid8E1506538F1D8C8626B4EDA7F7D6163DACF2C3C4.aspx?s=gridview#L15 [ ^ ]
This is what i found, it''s considered as the best practice while exporting a GridView to Excel and it works like a charm.
have a look at the link...
http://www.koders.com/csharp/fid8E1506538F1D8C8626B4EDA7F7D6163DACF2C3C4.aspx?s=gridview#L15[^]


请访问以下链接:



http ://aakarsoft.com/wordpress/index.php/export-gridview-data-to-excel-xlsx-without-using-htmltextwriter-in-asp-net/ [ ^ ]
Kindly visit following link:

http://aakarsoft.com/wordpress/index.php/export-gridview-data-to-excel-xlsx-without-using-htmltextwriter-in-asp-net/[^]


这篇关于如何在不导出gridview控件的情况下将gridview导出为ex​​cel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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