Xceed DataGrid for WPF v7.3 Documentation

In This Topic
    Exporting to Excel (ExportToExcel Method)
    In This Topic

    The following example demonstrates how to export the content of a grid to Excel using the grid's ExportToExcel method.

    XAML
    Copy Code
    <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
      <Grid.Resources>
         <xcdg:DataGridCollectionViewSource x:Key="cvs_orders"
                                            Source="{Binding Source={x:Static Application.Current}, Path=Orders}">
            <xcdg:DataGridCollectionViewSource.GroupDescriptions>
               <xcdg:DataGridGroupDescription PropertyName="ShipCountry" />
            </xcdg:DataGridCollectionViewSource.GroupDescriptions>
         </xcdg:DataGridCollectionViewSource>
      </Grid.Resources>
      <DockPanel>
         <Button Content="Export"
                 Click="ExportButton_Click"
                 DockPanel.Dock="Top" />
         <xcdg:DataGridControl x:Name="OrdersGrid"
                               ItemsSource="{Binding Source={StaticResource cvs_orders}}"/>
      </DockPanel>
    </Grid>

    The following code provides the code-behind implementation of the button's Click event in which the grid's ExportToExcel method is called.

    VB.NET
    Copy Code
    Private Sub ExportButton_Click( ByVal sender As Object, ByVal e As RoutedEventArgs )
      Me.OrdersGrid.ExportToExcel( "d:\orders.xls" )
    End Sub
    C#
    Copy Code
    private void ExportButton_Click( object sender, RoutedEventArgs e )
    {
     this.OrdersGrid.ExportToExcel( "d:\\orders.xls" );
    }