Click here to Skip to main content
14,242,862 members
Rate this:
Please Sign up or sign in to vote.
See more:
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();
Posted
Updated 16-Mar-11 19:56pm
v3
Comments
Prerak Patel 17-Mar-11 1:20am
   
How do you export?
Raj.rcr 17-Mar-11 1:32am
   
could u plz post ur code? so that some one can try to rectify this issue.
Nischal Bhatt 17-Mar-11 1:46am
   
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();
Rate this:
Please Sign up or sign in to vote.

Solution 1

you can use open source library called iTextSharp. With this you can export your gridview data.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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[^]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100