Click here to Skip to main content
15,901,284 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview, i have used datatable for that gridview. I want to export all the data from datatable to exel. Not from gridview.
Posted
Comments
Sandeep Mewara 26-May-11 10:43am    
Ok. So? Tried anyhing?

See Below Code (Its not a whole code,but gives u idea),
u need to add content-type,header

C++
DataGrid dg = new DataGrid();
        dg.Dispose();
        dg.DataSource =dt; //Your Datatable
        dg.DataBind();
        dg.HeaderStyle.Font.Bold = true;
                StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        dg.RenderControl(hw);
        Response.Write(sw.ToString());
 
Share this answer
 
v3
Try
MSDN-[Export dataTable to Excel from C#][^]
Datatable to Excel[^]
having same question with some perfect solution specially take a look of Sandeep Aparajit answer he tries to make a function which enable you to export datatable to Excel.
 
Share this answer
 
v2
also see this link and try to understand code... it will more help you

http://social.msdn.microsoft.com/Forums/en-GB/csharpgeneral/thread/5486f0dd-c168-4cea-bb99-03c92254c8a1[^]
 
Share this answer
 

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