RadGridView export to Excel creates empty file

3 posts, 1 answers
  1. Niraj
    Niraj avatar
    4 posts
    Member since:
    Oct 2015

    Posted 25 Feb 2016 Link to this post

    <t:RadGridView x:Name="Logs">
       <t:RadGridView.Columns>
           <t:GridViewDataColumn CellTemplateSelector="{StaticResource IconTemplateSelector}" />
           <t:GridViewDataColumn DataMemberBinding="{Binding LogLevel,Mode=OneWay}" Header="Level"
                            CellStyle="{StaticResource PaddedCell}"/>                
           <t:GridViewDataColumn DataMemberBinding="{Binding LogID,Mode=OneWay}" 
                            Header="LogID"/>
           <t:GridViewDataColumn DataMemberBinding="{Binding MachineDateTime,Mode=OneWay}"
                            Header="Machine Time"
                            CellStyle="{StaticResource PaddedCell}"/>
           <t:GridViewDataColumn DataMemberBinding="{Binding Occured, Mode=OneWay}"
                            Header="Occured" 
                            CellStyleSelector="{StaticResource ColorSelector}"/>
           <t:GridViewDataColumn DataMemberBinding="{Binding System,Mode=OneWay}"
                            Header="System"
                            CellStyle="{StaticResource PaddedCell}" />
           <t:GridViewDataColumn DataMemberBinding="{Binding Mode,Mode=OneWay}"
                            Header="Mode"
                            CellStyle="{StaticResource PaddedCell}" />
           <t:GridViewDataColumn DataMemberBinding="{Binding CallingClass,Mode=OneWay}"
                            Header="Calling Class"
                            CellStyle="{StaticResource PaddedCell}" />
           <t:GridViewDataColumn DataMemberBinding="{Binding Message,Mode=OneWay}"
                            Header="Message"
                            CellStyle="{StaticResource PaddedCell}" />
           <t:GridViewDataColumn DataMemberBinding="{Binding Exception,Mode=OneWay}"
                            Header="Exception" 
                            CellStyle="{StaticResource PaddedCell}" /> 
       </t:RadGridView.Columns>                     
    </telerik:RadGridView>

     

    I have above data-bound RadGridView (named Logs) and I am trying to export its contents, but it always results into an empty exported file.

    And I try to export the contents of RadGridView with below code:

    private void ExportLogs()
    {
        using (var stream = File.Create(filepath))
        {
              Logs.Export(stream,
                     new GridViewExportOptions()
                     {
                         Format = ExportFormat.ExcelML,
                         ShowColumnHeaders = true,
                         ShowColumnFooters = false,
                         ShowGroupFooters = false,
                     });   
         }
     }

    No exceptions or warning received.
    Any help would be appreciated. Thank you.
  2. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    566 posts

    Posted 01 Mar 2016 Link to this post

    Hello Niraj,

    I have created a sample project as showed in the Export article of our documentation, which successfully exports its content in a .xls file in a given directory.

    Could you please have a look at it and see how it differs from your approach?
    Could you also confirm that .xls is set as the file extension for the newly-created file?

    Should the issue persist, could you please provide a sample project for me to examine so that I can further assist you with your case?

    Regards,
    Dilyan Traykov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. Niraj
    Niraj avatar
    4 posts
    Member since:
    Oct 2015

    Posted 10 Mar 2016 in reply to Dilyan Traykov Link to this post

    Dear Dilyan,

    Thank you for the sample code and sorry for coming back late as I didn't had a chance to test your code.

    The problem with my code was that due to threading the GridView as accessed from non-UI thread, which lead contents of GridView to be in non-accessible state. Then I tried to call the Export function from UI thread and it worked as expected.

    Again thank you very much for your quick response, I really appreciate it.

    Niraj

Back to Top