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

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

1 Answer 67 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mohd
Top achievements
Rank 1
Mohd asked on 21 Dec 2011, 02:10 PM
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

1 Answer, 1 is accepted

Sort by
0
Mohd
Top achievements
Rank 1
answered on 04 Jan 2012, 12:34 PM
Long time no reply
Still Waiting..  :(
Tags
GridView
Asked by
Mohd
Top achievements
Rank 1
Answers by
Mohd
Top achievements
Rank 1
Share this question
or