Below is an image of the Demo that I created you can click on and try out.
This control uses the same set of Excel Files I explained about previously in my last post. In order to get this control to work in your project, follow the steps listed below:
1.) Add the Excel folder contained in the Source Code below to your Silverlight project.
2.) Add the Excel Datagrid Control to your XAML. Below shows the minimal XAML required to setup and reference the Excel Datagrid in XAML. This example only uses DataGridTextColumns, but you can also use template columns containing TextBlocks, TextBoxes, HyperLinkButtons, and Grids or StackPanels containing child controls. Make sure you replace "ExcelSilverlightDemo" with whatever the name of your project is.
<UserControl x:Class="ExcelSilverlightDemo.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:Excel="clr-namespace:ExcelSilverlightDemo.Excel">
<Grid x:Name="LayoutRoot" Background="Black" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="700">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button x:Name="ExportButton" Width="150" Content="Export to Excel" HorizontalAlignment="Right" Grid.Row="1" Canvas.ZIndex="5" Height="25" Click="ExportToExcel_Click" />
<Excel:DataGrid x:Name="dgDemo" AutoGenerateColumns="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="1">
<data:DataGrid.Columns>
<data:DataGridTextColumn Header="ID" Binding="{Binding ID}" IsReadOnly="True" Width="40" />
<data:DataGridTextColumn Header="Part Number" Binding="{Binding PartNumber}" IsReadOnly="True" />
<data:DataGridTextColumn Header="Part Name" Binding="{Binding PartName}" IsReadOnly="True" Width="100" />
<data:DataGridTextColumn Header="Made" Binding="{Binding MadeDate}" IsReadOnly="True" Width="200" />
<data:DataGridTextColumn Header="Quantity" Binding="{Binding Quantity}" IsReadOnly="True" Width="50" />
</data:DataGrid.Columns>
</Excel:DataGrid>
</Grid>
</UserControl>
3.) Add a button control to your XAML and then include the "Export" Method to the Button's Click event.
That's pretty much it. Build and run the project. When you click the export button, the "Save As" Dialog Box appears shown below. All you have to do is enter the file name and click save, and the file will be created to that location client-side. Depending on your operating system or settings, the file may just appear as a regular XML file. However it should open up in Microsoft Excel 2007 when you click on it.
<?xml version="1.0" encoding="utf-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet">
<DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>Silverlight</Author>
<LastAuthor>Silverlight</LastAuthor>
<Created>9/15/2009 1:02:04 PM</Created>
<LastSaved>9/15/2009 1:02:04 PM</LastSaved>
<Company>Your Company Name</Company>
<Version>12.00</Version>
</DocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>12015</WindowHeight>
<WindowWidth>20055</WindowWidth>
<WindowTopX>480</WindowTopX>
<WindowTopY>150</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<Alignment ss:Horizontal="Left" ss:Vertical="Center" />
<Borders />
<Font ss:FontName="Arial" ss:Size="10" ss:Color="#000000" />
<Interior ss:Color="#FFFFFF" ss:Pattern="Solid" />
<NumberFormat />
<Protection />
</Style>
<Style ss:ID="HeaderStyle" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1" />
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
</Borders>
<Font ss:FontName="Arial" ss:Size="10" ss:Color="#FFFFFF" ss:Bold="1" />
<Interior ss:Color="#000000" ss:Pattern="Solid" />
<NumberFormat />
<Protection />
</Style>
<Style ss:ID="ItemStyle" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<Alignment ss:Horizontal="Left" ss:Vertical="Center" ss:WrapText="1" />
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1" />
<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1" />
<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1" />
<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1" />
</Borders>
<Font ss:FontName="Arial" ss:Size="10" ss:Color="#000000" />
<Interior ss:Color="#FFFFFF" ss:Pattern="Solid" />
<NumberFormat />
<Protection />
</Style>
</Styles>
<Worksheet ss:Name="Data Export" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
<Table ss:ExpandedColumnCount="5" ss:ExpandedRowCount="51" ss:FullColumns="5" ss:FullRows="51" ss:DefaultRowHeight="15">
<Column ss:AutoFitWidth="0" ss:Width="40" />
<Column ss:AutoFitWidth="0" ss:Width="100" />
<Column ss:AutoFitWidth="0" ss:Width="100" />
<Column ss:AutoFitWidth="0" ss:Width="200" />
<Column ss:AutoFitWidth="0" ss:Width="50" />
<Row ss:Index="1" ss:AutoFitHeight="0" ss:Height="24">
<Cell ss:Index="1" ss:StyleID="HeaderStyle" ss:MergeAcross="0">
<Data ss:Type="String">ID</Data>
</Cell>
<Cell ss:Index="2" ss:StyleID="HeaderStyle" ss:MergeAcross="0">
<Data ss:Type="String">Part Number</Data>
</Cell>
<Cell ss:Index="3" ss:StyleID="HeaderStyle" ss:MergeAcross="0">
<Data ss:Type="String">Part Name</Data>
</Cell>
<Cell ss:Index="4" ss:StyleID="HeaderStyle" ss:MergeAcross="0">
<Data ss:Type="String">Made</Data>
</Cell>
<Cell ss:Index="5" ss:StyleID="HeaderStyle" ss:MergeAcross="0">
<Data ss:Type="String">Quantity</Data>
</Cell>
</Row>
<Row ss:Index="2" ss:AutoFitHeight="0" ss:Height="24">
<Cell ss:Index="1" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="Number">1</Data>
</Cell>
<Cell ss:Index="2" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">F9K-1</Data>
</Cell>
<Cell ss:Index="3" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">Part 1</Data>
</Cell>
<Cell ss:Index="4" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">9/16/2009 1:03:05 PM</Data>
</Cell>
<Cell ss:Index="5" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="Number">101</Data>
</Cell>
</Row>
<Row ss:Index="3" ss:AutoFitHeight="0" ss:Height="24">
<Cell ss:Index="1" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="Number">2</Data>
</Cell>
<Cell ss:Index="2" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">F9K-2</Data>
</Cell>
<Cell ss:Index="3" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">Part 2</Data>
</Cell>
<Cell ss:Index="4" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">9/17/2009 1:04:06 PM</Data>
</Cell>
<Cell ss:Index="5" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="Number">102</Data>
</Cell>
</Row>
<Row ss:Index="4" ss:AutoFitHeight="0" ss:Height="24">
<Cell ss:Index="1" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="Number">3</Data>
</Cell>
<Cell ss:Index="2" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">F9K-3</Data>
</Cell>
<Cell ss:Index="3" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">Part 3</Data>
</Cell>
<Cell ss:Index="4" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">9/18/2009 1:05:07 PM</Data>
</Cell>
<Cell ss:Index="5" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="Number">103</Data>
</Cell>
</Row>
<Row ss:Index="5" ss:AutoFitHeight="0" ss:Height="24">
<Cell ss:Index="1" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="Number">4</Data>
</Cell>
<Cell ss:Index="2" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">F9K-4</Data>
</Cell>
<Cell ss:Index="3" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">Part 4</Data>
</Cell>
<Cell ss:Index="4" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="String">9/19/2009 1:06:08 PM</Data>
</Cell>
<Cell ss:Index="5" ss:StyleID="ItemStyle" ss:MergeAcross="0">
<Data ss:Type="Number">104</Data>
</Cell>
</Row>
</Table>
</Worksheet>
</Workbook>
In the future I plan to add additional features such as charts and graphs. In the meantime, I hope these ideas save other developers time.