Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET
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 16-Mar-11 19:19pm
Edited 16-Mar-11 19:56pm
v3
Comments
Prerak Patel at 17-Mar-11 1:20am
   
How do you export?
Raj.rcr at 17-Mar-11 1:32am
   
could u plz post ur code? so that some one can try to rectify this issue.
Nischal Bhatt at 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: bad
good
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.
  Permalink  
Rate this: bad
good
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[^]
  Permalink  
v2

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

  Print Answers RSS
0 CPallini 330
1 Sergey Alexandrovich Kryukov 313
2 George Jonsson 291
3 Prasad Avunoori 155
4 OriginalGriff 149
0 OriginalGriff 4,623
1 CPallini 3,410
2 Sergey Alexandrovich Kryukov 2,929
3 George Jonsson 2,319
4 Gihan Liyanage 2,077


Advertise | Privacy | Mobile
Web04 | 2.8.140905.1 | Last Updated 23 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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