Solution 4 : Export Silverlight DataGrid to Excel XML

While ASP.NET GridView control supports data export to Excel, Silverlight DataGrid control does not. To implement the data export, you need to retrieve data from the DataGrid and write the data to an Excel XML file (Office Open XML File Format).

1.       Use Microsoft Excel application to create a new Excel spreadsheet with the format that you want for the data export. Enter a couple of dummy data and Save As XML spreadsheet. This is your Excel template.

2.      Copy all the source of the above Excel template to where you will develop the data export function such as in the ExportToExcelButton_Click event. The following are partial source.

3.      Use Silverlight SaveFileDialog control to create a StreamWriter instance. Call WriteLine method of the  instance in each line of the copied Excel template source.

4.      Running the code now, you should be able to export data to an Excel XML file, which is identical to the one you created originally in the step 1. You can use this to verify that your base code is working.

5.      Replace data-driven lines with dynamic data.

6.      Retrieve data from ItemsSource of the DataGrid and replace the dummy data lines with the retrieved data. (Assume entity class of Customer with single property of Name).

Published Wednesday, December 16, 2009 7:52 PM by StanleyGu

Comments

# re: Solution 4 : Export Silverlight DataGrid to Excel XML

Thursday, May 26, 2011 6:21 AM by weblogs.asp.net

Export silverlight datagrid to excel xml.. Neat :)

# re: Solution 4 : Export Silverlight DataGrid to Excel XML

Sunday, August 21, 2011 10:45 PM by jason tb

for exporting Silverlight DataGrid to Excel 97~2010 WITHOUT OLE AUTOMATION

www.e-iceblue.com/.../excel-for-net-introduce.html

# re: Solution 4 : Export Silverlight DataGrid to Excel XML

Wednesday, November 16, 2011 1:08 PM by Bhavik

How do you do it while following MVVM pattern?

# re: Solution 4 : Export Silverlight DataGrid to Excel XML

Monday, May 20, 2013 9:06 AM by Nelms

I enjoy checking your site. Kudos!