Download to Excel Behavior for Silverlight DataGrid
I wrote a behavior to export a DataGrid to Excel. Silverlight allows saving files, and this behavior transforms a DataGrid into a .csv file.
To use, add a reference to your project to the assembly, and you will see the DownloadToExcel behavior under the Assets tab:
Add the behavior to any UIElement. In this case, I added it to a button:
The default event selected on the button is the Click event, which is what we want. Set the Target Object by clicking on the little target icon and then choosing the data grid you want to export to excel:
Below is a screenshot of the test app. When we run it and click the button, we are prompted to save the file. This is the DataGrid in the sample code:
The resulting .CSV file--which opens in Excel by default--it looks like this:
Download just the .DLL or the source code with sample app.
Thanks to stackoverflow and those who responded to this question for giving me insight.
Labels: behavior, silverlight
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home