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

Export Excel Date Format Lost

3 Answers 99 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Wang
Top achievements
Rank 1
Wang asked on 10 Aug 2012, 11:02 AM

Hi Guys,
    At first , please let me simply introduce my project state .

    server-side : wcf service (data service layer \ data interface layer)
    client-side   : silverlight4.0 (referred assembly: Telerik.Windows.Controls 2011.2.712.1040 \Telerik.Windows.Controls.GridView 2011.2.712.1040) 

    About GridView Export Function , please see the following main code :

            SaveFileDialog dialog = new SaveFileDialog(); 
         dialog.DefaultExt = extension; 
         dialog.Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, selectedItem); 
         dialog.FilterIndex = 1; 
         if (dialog.ShowDialog() == true
         
             using (Stream stream = dialog.OpenFile()) 
             
                 GridViewExportOptions exportOptions = new GridViewExportOptions(); 
                 exportOptions.Format = format; 
                 exportOptions.ShowColumnHeaders = true
                 radgridview.Export(stream, exportOptions); 
             
         }
        

        At this moment , the issue i have faced was the datetime value displayed abnormally . please see the illustration by attachment.
        Should I set the gridview some export option or else ? How to solve it ?

        please give me some advices , I am looking forward to your help .
        thanks.

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 15 Aug 2012, 08:19 AM
Hello,

 I have tested exporting DateTime value on this online demo. The values were exported as they are displayed in the GridView. You can test the export using different export format. May I ask you to share a little bit more information on how is the DateTime column defined and displayed in the GridView before the export?

Greetings,
Didie
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Wang
Top achievements
Rank 1
answered on 27 Sep 2012, 06:43 AM

Hi Didie,
            I am so sorry about this delaying reply.
           
            About the DateTime column defined and displayed in the GridView before the export ,please see the following main code :
            
            1)Views Layer: demo1.xaml

<telerik:RadGridView Grid.Row="0" AutoGenerateColumns="True" ItemsSource="{Binding Path=EventDataSource,Mode=OneWay}"
             Name="dgEvent" AutoExpandGroups="True" CanUserFreezeColumns="False" IsReadOnly="True" ShowGroupPanel="True"
             HorizontalAlignment="Stretch" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch"
             RowIndicatorVisibility="Collapsed">
</telerik:RadGridView>

             2)ViewMode Layer : demo1.cs
    
namespace Demos.Module.ViewModel
{
        //...
        private IEnumerable _eventDataSource;
        public IEnumerable EventDataSource
        {
            get
            {
                return _eventDataSource;
            }
            private set
            {
                _eventDataSource = value;
                this.RaisePropertyChanged("EventDataSource");
            }
        }
 
    public class DemoViewModel : INotifyPropertyChanged
    {          
          public EventViewViewModel()
          {
                Init();
                GetDataCommand = new DelegateCommand<object>((emptyArg) =>
                {
                       //...
                       _client.GetDatasCompleted += new EventHandler<GetDatasCompletedEventArgs>
                        (_client_GetDatasCompleted);
                    _client.GetDatasAsync();
                }
          }
          void _client_GetDatasCompleted(object sender, GetDatasCompletedEventArgs e)
          {
                if (e.Error != null)
               {
                          //Get all events data failed.
                          return;
               }
               var result = e.Result;
               if(result!=null&&result.count>0)
               {
                     EventDataSource = result ;
               } 
          }
     }
}

           Those datetime values  automatically binded to one column of RadGridView are coming from some table records in sql database. the data type of  'EventTime' field is 'DateTime'  in sql table definition.

           At this moment , the issue i have faced was the datetime value displayed abnormally on the exported excel document.
           please see the illustration by attachment.

           please give me some advices , I am in urgent need of your more helps .
           thanks.
        

0
Dimitrina
Telerik team
answered on 01 Oct 2012, 12:59 PM
Hi,

 Would it be possible for you to isolate the issue in a demo project and send it to us? You can take a look at this blog post for a reference on how to isolate a problem in a sample project.

Greetings,
Didie
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Wang
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Wang
Top achievements
Rank 1
Share this question
or