This is a migrated thread and some comments may be shown as answers.

Exporting Hierarchical RadGridView showing error in Excell Sheet

6 Answers 151 Views
GridView
This is a migrated thread and some comments may be shown as answers.
hirak
Top achievements
Rank 1
hirak asked on 21 Apr 2011, 08:03 AM
Hi,

I am using Telerik RadGridView which is implemented in a hierarchical manner in WPF Windows application.

While exporting to Excell I am getting the following error message in the Excell sheet, instead of displaying data.

[QCVG: Key=Private Capital; ItemCount=3; HasSubgroups=False; ParentGroup=[QCVG: Key=Alternatives; ItemCount=6; HasSubgroups=True; ParentGroup=[QCVG: Key=Root; ItemCount=6; HasSubgroups=True; ParentGroup=null];];];

Is there any solution to this issue.

Any quick sample code will be highly usefull to resolve this issue.

Thanks & Regards,
Hirak

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 21 Apr 2011, 08:14 AM
Hello,

 The grid will not export group footer by default. You need to handle ElementExporting event and provide values similar to this demo

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
hirak
Top achievements
Rank 1
answered on 21 Apr 2011, 08:33 AM
Hi Vlad,

Thanks for your reply. I tried exactly the same code what you have referred me to follow in your demo.
But still I got the same error.
Please see my XAML code which I am using and provide me a solution how to export to excell in this scenario.

My XAML code is as follows:

 <Grid x:Name="GridNonMarketable" >
        <telerik:RadGridView Grid.Row="0" x:Name="RadGridNonMarketableSummary" ElementExporting="RadGridNonMarketableSummary_ElementExporting" RowLoaded="RadGridNonMarketableSummary_RowLoaded" Loaded="RadGridNonMarketableSummary_Loaded"  telerikControls:StyleManager.Theme="Office_Blue" IsReadOnly="True"  ItemsSource="{Binding TradeNonMarketableData.NonMarketableSummaryModel}" IsFilteringAllowed="False"  CanUserFreezeColumns="False"  AutoGenerateColumns="False" AutoExpandGroups="True"  >
            <telerik:RadGridView.ChildTableDefinitions>
                <telerik:GridViewTableDefinition   />
            </telerik:RadGridView.ChildTableDefinitions>
            <telerik:RadGridView.RowStyle>
                <Style TargetType="{x:Type telerik:GridViewRow}">
                    <Setter Property="IsExpanded" Value="True"/>
                </Style>
            </telerik:RadGridView.RowStyle>
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Investment Category Name" DataMemberBinding="{Binding InvestmentCategoryName}" IsVisible="False"   />
                <telerik:GridViewDataColumn Header="Asset Class Name" DataMemberBinding="{Binding AssetClassName}"  IsVisible="False"  />
                <telerik:GridViewDataColumn Header="Sbu" DataMemberBinding="{Binding SbuName}" Width="125" TextWrapping="Wrap"/>
                <telerik:GridViewDataColumn Header="Total Value" DataMemberBinding="{Binding TotalValue, StringFormat={}{0:c}}" HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap">
                    <telerik:GridViewDataColumn.AggregateFunctions>
                        <telerik:SumFunction Caption="Total :" ResultFormatString="{}{0:c}" />
                    </telerik:GridViewDataColumn.AggregateFunctions>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="Target Min" DataMemberBinding="{Binding TargetMin, StringFormat={}{0:n2}}"  HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap"/>
                <telerik:GridViewDataColumn Header="Target Max" DataMemberBinding="{Binding TargetMax, StringFormat={}{0:n2}}"  HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap"/>
                <telerik:GridViewDataColumn Header="Target Total" DataMemberBinding="{Binding TargetTotal, StringFormat={}{0:n2}}"  HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap"/>
                <telerik:GridViewDataColumn Header="Total Actual" DataMemberBinding="{Binding TotalActual, StringFormat={}{0:n2}}"  HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap"/>
                <telerik:GridViewDataColumn Header="Variance" DataMemberBinding="{Binding Variance, StringFormat={}{0:n2}}"  HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap">
                    <telerik:GridViewDataColumn.CellStyle>
                        <Style TargetType="telerik:GridViewCell">
                            <Setter Property="Foreground" Value="{Binding TotalRange, Converter={StaticResource RangeConverter}}" />
                        </Style>
                    </telerik:GridViewDataColumn.CellStyle>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Header="Total Range" DataMemberBinding="{Binding TotalRange}"  HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap">
                    <telerik:GridViewDataColumn.CellStyle>
                        <Style TargetType="telerik:GridViewCell">
                            <Setter Property="Foreground" Value="{Binding TotalRange, Converter={StaticResource RangeConverter}}" />
                        </Style>
                    </telerik:GridViewDataColumn.CellStyle>
                </telerik:GridViewDataColumn>
            </telerik:RadGridView.Columns>
            <telerik:RadGridView.HierarchyChildTemplate>
                <DataTemplate>
                    <telerik:RadGridView x:Name="RadGridNonMarketableDetail" telerikControls:StyleManager.Theme="Windows7" CanUserFreezeColumns="False" AutoGenerateColumns="False" IsFilteringAllowed="False" ItemsSource="{Binding NonMarketableDetailModel}"  ShowGroupPanel="False" IsReadOnly="True">
                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding FundName}" Header="Fund Name" Width="200" TextWrapping="Wrap"/>
                            <telerik:GridViewDataColumn  Header="Value / Unadjusted Value" HeaderTextAlignment="Right" TextAlignment="Right" Width="150" TextWrapping="Wrap" >
                                <telerik:GridViewDataColumn.CellTemplate>
                                    <DataTemplate>
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding Value,StringFormat={}{0:c}}"></TextBlock>
                                            <TextBlock Text=" / "></TextBlock>
                                            <TextBlock Text="{Binding UnAdjustedValue,StringFormat={}{0:c}}"></TextBlock>
                                        </StackPanel>
                                    </DataTemplate>
                                </telerik:GridViewDataColumn.CellTemplate>
                            </telerik:GridViewDataColumn>

                            <telerik:GridViewDataColumn DataMemberBinding="{Binding ValueDate, StringFormat={}{0:d}}" Header="Value Date" HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding TotalActual, StringFormat={}{0:n3}}" Header="Total Actual" HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding FundCode}" Header="Fund Code" HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding CalledToDate, StringFormat={}{0:c}}" Header="Called To Date" HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding Commitment, StringFormat={}{0:c}}" Header="Commitment" HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding TotalDistributions, StringFormat={}{0:c}}" Header="Total Distributions" HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap"/>
                            <telerik:GridViewDataColumn DataMemberBinding="{Binding ToBeCalled, StringFormat={}{0:c}}" Header="To Be Called" HeaderTextAlignment="Right" TextAlignment="Right" Width="90" TextWrapping="Wrap"/>
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>
                </DataTemplate>
            </telerik:RadGridView.HierarchyChildTemplate>
        </telerik:RadGridView>
        <!--<telerik:RadButton Name="ExporttoExcel" Margin="722,-33,0,0" Style="{DynamicResource NormalButtonStyle}" Content="Export to Excel"  Command="{Binding ExportToExcelCommand}" Width="102" HorizontalAlignment="Right" VerticalAlignment="Top" Height="27" CommandParameter="{Binding}"/>-->
        <telerik:RadButton Name="ExporttoExcel" Margin="722,-33,0,0" Style="{DynamicResource NormalButtonStyle}" Content="Export to Excel" Width="102" HorizontalAlignment="Right" VerticalAlignment="Top" Height="27" Click="ExporttoExcel_Click"/>
    </Grid>

Please see that in my code I am using two RadGridView controls.

Any quick sample to this solution will be highly appreciated.

Thanks & Regards,
Hirak
0
Vlad
Telerik team
answered on 21 Apr 2011, 08:41 AM
Hello,

 Can you post the ElementExporting code as well?

All the best,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
hirak
Top achievements
Rank 1
answered on 21 Apr 2011, 09:29 AM
Hi Vlad,

Please check the ElementExporting function implementation as mentioned below:

private void RadGridNonMarketableSummary_ElementExporting(object sender, Telerik.Windows.Controls.GridViewElementExportingEventArgs e)
        {
            if (e.Element == Telerik.Windows.Controls.ExportElement.HeaderRow || e.Element == Telerik.Windows.Controls.ExportElement.FooterRow
               || e.Element == Telerik.Windows.Controls.ExportElement.GroupFooterRow)
            {
                //e.Background = HeaderBackgroundPicker.SelectedColor;
               // e.Foreground = HeaderForegroundPicker.SelectedColor;
                e.Background = Colors.LightGray;
                e.Foreground = Colors.Black;
                e.FontSize = 20;
                e.FontWeight = FontWeights.Bold;
            }
            else if (e.Element == Telerik.Windows.Controls.ExportElement.Row)
            {
                //e.Background = RowBackgroundPicker.SelectedColor;
                //e.Foreground = RowForegroundPicker.SelectedColor;
                e.Background = Colors.LightGray;
                e.Foreground = Colors.Black;
            }
            else if (e.Element == Telerik.Windows.Controls.ExportElement.Cell &&
                e.Value != null && e.Value.Equals("Chocolade"))
            {
                e.FontFamily = new FontFamily("Verdana");
                e.Background = Colors.LightGray;
                e.Foreground = Colors.Blue;
            }
            else if (e.Element == Telerik.Windows.Controls.ExportElement.GroupHeaderRow)
            {
                e.FontFamily = new FontFamily("Verdana");
                e.Background = Colors.LightGray;
                e.Height = 30;
            }
            else if (e.Element == Telerik.Windows.Controls.ExportElement.GroupHeaderCell &&
                e.Value != null && e.Value.Equals("Chocolade"))
            {
                e.Value = "MyNewValue";
            }
            else if (e.Element == Telerik.Windows.Controls.ExportElement.GroupFooterCell)
            {
                Telerik.Windows.Controls.GridViewDataColumn column = e.Context as Telerik.Windows.Controls.GridViewDataColumn;
                Telerik.Windows.Data.QueryableCollectionViewGroup qcvGroup = e.Value as Telerik.Windows.Data.QueryableCollectionViewGroup;

                if (column != null && qcvGroup != null && column.AggregateFunctions.Count() > 0)
                {
                    e.Value = GetAggregates(qcvGroup, column);
                }
            }
        }

        private string GetAggregates(Telerik.Windows.Data.QueryableCollectionViewGroup group, Telerik.Windows.Controls.GridViewDataColumn column)
        {
            List<string> aggregates = new List<string>();

            foreach (Telerik.Windows.Data.AggregateFunction f in column.AggregateFunctions)
            {
                foreach (Telerik.Windows.Data.AggregateResult r in group.AggregateResults)
                {
                    if (f.FunctionName == r.FunctionName && r.FormattedValue != null)
                    {
                        aggregates.Add(r.FormattedValue.ToString());
                    }
                }
            }

            return String.Join(",", aggregates.ToArray());
        }

Please, let me know any solution to this issue.

Thanks & Regards,
Hirak
0
hirak
Top achievements
Rank 1
answered on 21 Apr 2011, 10:24 AM
HI Vlad,

Could you please suggest me any quick solution to this issue.

Thanks & Regards,
Hirak
0
Vlad
Telerik team
answered on 21 Apr 2011, 11:43 AM
Hello,

 Unfortunately I'm not sure why this code does not work at your end - as on our demo. Please send us an example application (via support ticket) where we can check your scenario and reproduce the problem.

Greetings,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
hirak
Top achievements
Rank 1
Answers by
Vlad
Telerik team
hirak
Top achievements
Rank 1
Share this question
or