Hi there,
my problem is I have a grid view, and I have tons of login in xaml which perform the grouping and aggregate function, some of the group header/footer may have a DataTemplate to host the data. When I export the grid using the native Export function, I have the following issue:
1. I lost the Group Header, the column I am used to group is not shown in UI and I disallow use to change the grouping
2. I lost the ColumnGroups
3. Some of the cell is incorrect datatype (e.g. number and was interpreted as date in Excel)
4. All the template data cannot be displayed, and what's generated is the datatype instead of the string value on the grid (same as copy from the grid directly using Ctrl-C)
Any help will be appreciated!
Here are some examples of the xaml:
1. Grid Definition
2. Column Group
3. Column (I have tons of column and just show two here, the 1st is used for grouping)
And here is the method in the code behind to export:
my problem is I have a grid view, and I have tons of login in xaml which perform the grouping and aggregate function, some of the group header/footer may have a DataTemplate to host the data. When I export the grid using the native Export function, I have the following issue:
1. I lost the Group Header, the column I am used to group is not shown in UI and I disallow use to change the grouping
2. I lost the ColumnGroups
3. Some of the cell is incorrect datatype (e.g. number and was interpreted as date in Excel)
4. All the template data cannot be displayed, and what's generated is the datatype instead of the string value on the grid (same as copy from the grid directly using Ctrl-C)
Any help will be appreciated!
Here are some examples of the xaml:
1. Grid Definition
<telerik:RadGridView Name="GridViewMyGrid" ItemsSource="{Binding MyCollection}" AutoGenerateColumns="False" IsReadOnly="True" CanUserFreezeColumns="False" GroupRenderMode="Flat" ShowColumnFooters="True" ShowGroupFooters="True" AutoExpandGroups="True" IsFilteringAllowed="False" ShowGroupPanel="False" FrozenColumnCount="2" SelectionMode="Extended" >2. Column Group
<telerik:RadGridView.ColumnGroups> <telerik:GridViewColumnGroup Name="Group1ColumnGroup" Header="Group1"> <telerik:GridViewColumnGroup.HeaderTemplate> <DataTemplate> <TextBlock Text="Group1" TextAlignment="Center" FontWeight="Bold"></TextBlock> </DataTemplate> </telerik:GridViewColumnGroup.HeaderTemplate> </telerik:GridViewColumnGroup>3. Column (I have tons of column and just show two here, the 1st is used for grouping)
<telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding GroupName}" ShowColumnWhenGrouped="False" /> <telerik:GridViewDataColumn Header="Item1" DataMemberBinding="{Binding Item1}"> <telerik:GridViewDataColumn.AggregateFunctions> <telerik:FirstFunction/> </telerik:GridViewDataColumn.AggregateFunctions> <telerik:GridViewDataColumn.GroupFooterTemplate> <DataTemplate> <TextBlock FontWeight="Bold"> <Run Text="Subtotal "/> <Run Text="{Binding Value.GroupName}"/> </TextBlock> </DataTemplate> </telerik:GridViewDataColumn.GroupFooterTemplate> <telerik:GridViewColumn.Footer> <TextBlock FontWeight="Bold"> <Run Text="Asset Total"/> </TextBlock> </telerik:GridViewColumn.Footer> </telerik:GridViewDataColumn>And here is the method in the code behind to export:
private void ButtonExportStrats_OnClick(object sender, RoutedEventArgs e) { var grid = GridViewMyGrid; var dialog = new SaveFileDialog(); dialog.DefaultExt = "*.xlsx"; dialog.Filter = "Excel Workbook (*.xlsx)|*.xlsx"; if (dialog.ShowDialog() == true) { Workbook book = null; using (var stream = new MemoryStream()) { grid.Export(stream, new GridViewExportOptions() { Format = ExportFormat.Csv, ShowColumnFooters = grid.ShowColumnFooters, ShowColumnHeaders = grid.ShowColumnHeaders, ShowGroupFooters = grid.ShowGroupFooters }); stream.Position = 0; book = new CsvFormatProvider().Import(stream); if (book != null) { var provider = new XlsxFormatProvider(); using (var output = dialog.OpenFile()) { provider.Export(book, output); } } } } }