Click here to Skip to main content
16,022,536 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai all,
am using .net 4.0 framework, i have one grid with data i have to export that to the excel ...
Please help me...
Posted
Comments
ImmeShea 26-Nov-15 7:46am    
The question is tagged with "WPF", but the provided answer is for ASP.NET's GridView control, so I'm not sure which GridView control are you referring to.
Nevertheless I would suggest you to check out this C# library for excel's workbooks. It is a general purpose library so you can use it in both WPF and ASP.NET and it can enable you to generate the required excel file from various sources (including from any of those controls)

1 solution

Hi please find the below code use it in button click event on the same form where grid is present
//export to excel
Response.Clear();
Response.Buffer= true;
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.ClearControls(dg);
dg.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
 
Share this answer
 
Comments
satyagrahi_2010 23-Jul-10 5:28am    
Reason for my vote of 2
some what fine.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900