Click here to Skip to main content
14,869,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to export data from WPF toolkit datagrid (which has the data from the SQL server database) to excel.

But when I search in the google, in all sites there is the method to export from asp.net or vb.net

Such methods are not get success in the WPF.

Pls help me through any sample code snippets
Posted

1 solution

I found this exchange with google:

WPF's DataGrid is a bit different than ASP.net's DataGrid. One way you can export to excel with WPF's DG is to use the DataGrid.CopyToClipboard command which makes a copy in a CSV, html, and text format. From there you can either just create a csv file or use the excel APIs to create an excel file. Hope that helps.



I might be in dire need of lunch but I can't find a CopyToClipboard command or anything like it for the WPF datagrid. Would it be possible for you to provide a brief code snippet because I'm scratching my head and clearly missing something obvious.

Sorry, I think what I meant to say was the built in copy functionality of DataGrid. DataGrid has a ClipboardCopyMode and does use a command to do a copy but the only way you can customize it is by overriding one of the protected copy methods. The default copy functionality does create the formats that I describe above so you should be able to export that to excel.




Google is easy. As for code snippets, you're on your own, but you should be able to develop the code for this in just a few lines.
   
v3

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