RadGrid Export to excel unable to maintain Decimal Format for number less than 4 digits

2 posts, 0 answers
  1. Mohd
    Mohd avatar
    19 posts
    Member since:
    Aug 2011

    Posted 21 Dec 2011 Link to this post

    Hi
    I am trying to export RadGrid to Excel but it seems that that for numbers less than 4 digits decimal formatting is not maintained in Excel
    my code in MainPage.xaml.cs
    public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
            }
            private void Button1_Click(object sender, RoutedEventArgs e)
            {
                string extension = "xls";
                SaveFileDialog dialog = new SaveFileDialog()
                {
                    DefaultExt = extension,
                    Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
                    FilterIndex = 1
                };
                if (dialog.ShowDialog() == true)
                {
                    using (Stream stream = dialog.OpenFile())
                    {
                       // MemoryStream ms = new MemoryStream();
                        clubsGrid.Export(stream,
                         new GridViewExportOptions()
                         {
                             Format = ExportFormat.Html,
                             ShowColumnHeaders = true,
                             ShowColumnFooters = true,
                             ShowGroupFooters = false,
                         });
                        //byte[] header = Encoding.UTF8.GetBytes("Premier League");
                        //stream.Write(header, 0, header.Length);
                        //stream.Write(ms.ToArray(), 0, ms.ToArray().Length);
                    }
                }
     
            }
        }

    and in xaml my code is like
    <UserControl.Resources>
           <my:MyViewModel x:Key="MyViewModel"/>
       </UserControl.Resources>
       <Grid x:Name="LayoutRoot"
             Background="White"
             DataContext="{StaticResource MyViewModel}">
           <Grid.RowDefinitions>
               <RowDefinition Height="*"/>
               <RowDefinition Height="Auto" />
           </Grid.RowDefinitions>
           <Grid.Resources>
               <DataTemplate x:Key="RowDetailsTemplate">
                   <telerik:RadGridView Name="playersGrid"
                                        ItemsSource="{Binding Players}"
                                        AutoGenerateColumns="False">
                       <telerik:RadGridView.Columns>
                           <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
                           <telerik:GridViewDataColumn DataMemberBinding="{Binding Number}"/>
                           <telerik:GridViewDataColumn DataMemberBinding="{Binding Position}"/>
                           <telerik:GridViewDataColumn DataMemberBinding="{Binding Country}"/>
                       </telerik:RadGridView.Columns>
                   </telerik:RadGridView>
               </DataTemplate>
           </Grid.Resources>
           <telerik:RadGridView Name="clubsGrid"
                                ItemsSource="{Binding Clubs}"
                                AutoGenerateColumns="False"
                                RowDetailsTemplate="{StaticResource RowDetailsTemplate}"
                                Margin="5,37,5,5" Grid.RowSpan="2">
               <telerik:RadGridView.Columns>
                   <telerik:GridViewToggleRowDetailsColumn/>
                   <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
                   <telerik:GridViewDataColumn DataMemberBinding="{Binding Established}"
                                               Header="Est."
                                               DataFormatString="{}{0:yyyy}"/>
                   <telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}"
                                               Header="Stadium"
                                               DataFormatString="{}{0:N2}"/>
                    
               </telerik:RadGridView.Columns>
           </telerik:RadGridView>
           <Button Grid.Row="1"
                   Content="Export"
                   Click="Button1_Click"
                   Margin="5"
                   HorizontalAlignment="Left"/>
       </Grid>

    While i have seperate class for Club, Player, Position and a ViewModel.
    I am attaching Screenshot for further reference.
    Any help would be great
    If possible provide some sample
    Thanks
  2. Mohd
    Mohd avatar
    19 posts
    Member since:
    Aug 2011

    Posted 04 Jan 2012 Link to this post

    Long time no reply
    Still Waiting..  :(
Back to Top