Can you export to Excel from a Silverlight DataGrid?

Export silverlight DataGrid to Excel Action.

Download demo project: DataGrid2Excel.zip

Download the action: DataGrid2ExcelAction.zip

UPDATE!

The Excel exporter now supports nested properties (ProductGroup.ProductType.Name). Thank you Chris Meijers for helping me with the code to loop through nested properties.

If you need to export data from Silverlight to Excel, you have a few options like using COM or creating Excel documents on the server. Another method is to create Excel XML and save this on the client with a FileSaveDialog. This is a very easy way to create a worksheet with a simple list of data.

export

To make this action I created an excel document, saved it as an XML file and used that XML as a template to create documents. At runtime I replace a data placeholder with the data from my DataGrid. I isolated the code and created a Silverlight TriggerAction.

How to use?

This export action is very basic. I have only tested it with a simple list of data and only in Excel 2007 on a Windows 7 machine. If you like the action and improve it in any way, please let me know and I’ll update it here.

Written by Loek van den Ouweland on 2010-10-21.
Questions regarding this artice? You can send them to the address below.