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

RadGridView export to Excel creates empty file

2 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Niraj
Top achievements
Rank 1
Niraj asked on 25 Feb 2016, 05:57 PM
<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 Answers, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 01 Mar 2016, 12:51 PM
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 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
0
Niraj
Top achievements
Rank 1
answered on 10 Mar 2016, 02:53 PM

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

Tags
GridView
Asked by
Niraj
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Niraj
Top achievements
Rank 1
Share this question
or