We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

NullReferenceException when exporting to Excel

Thread ID:

Created:

Updated:

Platform:

Replies:

130625 May 22,2017 05:15 PM May 24,2017 12:08 AM WPF 1
loading
Tags: SfDataGrid
John Vong
Asked On May 22, 2017 05:15 PM

     When I call the ExportToExcel extension method like:

          var options = new ExcelExportingOptions();
          options.ExcelVersion = ExcelVersion.Excel2013;
                
          var excelEngine = datagrid1.ExportToExcel(datagrid1.View, options);
          var workBook = excelEngine.Excel.Workbooks[0];

I get a null reference exception if I have more than one GridViewDefinition in a nested DetailsViewDefinition.If the DetailsViewDefinition is 
at the first level then multiple GridViewDefinitions works. 
My XAML looks like this:
<syncfusion:SfDataGrid x:Name="datagrid1" HideEmptyGridViewDefinition="True" ItemsSource="{Binding CommissionPlans}" SelectedItem="{Binding SelectedPlan}" 
                                       AutoGenerateColumns="False" Margin="5" AllowResizingColumns="True" AutoGenerateRelations="True" ColumnSizer="Auto">
                    <syncfusion:SfDataGrid.Columns>
                        <syncfusion:GridTextColumn HeaderText="Location" MappingName="StoreName" MinimumWidth="200" />
                        <syncfusion:GridDateTimeColumn HeaderText="Start" MappingName="PlanBegin" />
                        <syncfusion:GridDateTimeColumn HeaderText="End" MappingName="PlanEnd" />
                        <syncfusion:GridTextColumn HeaderText="Rep" MappingName="RepName" MinimumWidth="175"/>
                        <syncfusion:GridTextColumn HeaderText="Is Active" MappingName="IsActive" />
                        <syncfusion:GridTextColumn HeaderText="Plan Type" MappingName="PlanType" />
                        <syncfusion:GridCurrencyColumn HeaderText="Base Pay" MappingName="BasePay" />
                        <syncfusion:GridCurrencyColumn HeaderText="Min. Comm." MappingName="MinComm" />
                        <syncfusion:GridPercentColumn HeaderText="Split Comm." MappingName="SplitCommRate" PercentEditMode="PercentMode" />
                    </syncfusion:SfDataGrid.Columns>
                    <syncfusion:SfDataGrid.DetailsViewDefinition>
                        <syncfusion:GridViewDefinition RelationalColumn="Incentives">
                            <syncfusion:GridViewDefinition.DataGrid>
                                <syncfusion:SfDataGrid x:Name="FirstLevelNestedGrid1" AllowResizingColumns="True"
                                       AutoGenerateColumns="False" AutoGenerateRelations="False" HideEmptyGridViewDefinition="True">
                                    <syncfusion:SfDataGrid.Columns>
                                        <syncfusion:GridTextColumn HeaderText="Incentive" MappingName="IncentiveTypeID" />
                                        <syncfusion:GridTextColumn HeaderText="Based On" MappingName="PIATypeID"/>
                                        <syncfusion:GridTextColumn HeaderText="Category" MappingName="Category.CategoryID"/>
                                        <syncfusion:GridTextColumn HeaderText="Description"  MappingName="Description" TextWrapping="Wrap" ColumnSizer="Auto"/>
                                        <syncfusion:GridTextColumn HeaderText="HasCondition" MappingName="HasSalesCondition"/>
                                    </syncfusion:SfDataGrid.Columns>                                    
                                    <syncfusion:SfDataGrid.DetailsViewDefinition>                                                                                
                                        <syncfusion:GridViewDefinition RelationalColumn="SelectedTieredCategoryMix">
                                            <syncfusion:GridViewDefinition.DataGrid>
                                                <syncfusion:SfDataGrid x:Name="SecondLevelNestedGrid1" AllowResizingColumns="True"
                                                                       AutoGenerateColumns="False" AutoGenerateRelations="False" ColumnSizer="Auto">
                                                    <syncfusion:SfDataGrid.Columns>
                                                        <syncfusion:GridTextColumn HeaderText="Categories" MappingName="CategoryID"/>
                                                    </syncfusion:SfDataGrid.Columns>
                                                </syncfusion:SfDataGrid>
                                            </syncfusion:GridViewDefinition.DataGrid>                                           
                                        </syncfusion:GridViewDefinition>
                                        <syncfusion:GridViewDefinition RelationalColumn="Tiers">
                                            <syncfusion:GridViewDefinition.DataGrid>
                                                <syncfusion:SfDataGrid x:Name="SecondLevelNestedGrid2" AllowResizingColumns="True"
                                                                       AutoGenerateColumns="False" AutoGenerateRelations="False" ColumnSizer="Auto">
                                                    <syncfusion:SfDataGrid.Columns>
                                                        <syncfusion:GridTextColumn HeaderText="Tier" MappingName="Tier"/>
                                                        <syncfusion:GridTextColumn HeaderText="Min" MappingName="TierMinStr"/>
                                                        <syncfusion:GridTextColumn HeaderText="Max" MappingName="TierMaxStr"/>
                                                        <syncfusion:GridTextColumn HeaderText="Value" MappingName="ValueStr" />                                                        
                                                    </syncfusion:SfDataGrid.Columns>
                                                </syncfusion:SfDataGrid>
                                            </syncfusion:GridViewDefinition.DataGrid>
                                        </syncfusion:GridViewDefinition>                                        
                                    </syncfusion:SfDataGrid.DetailsViewDefinition>                                   
                                </syncfusion:SfDataGrid>
                            </syncfusion:GridViewDefinition.DataGrid>
                        </syncfusion:GridViewDefinition>
                    </syncfusion:SfDataGrid.DetailsViewDefinition>
                </syncfusion:SfDataGrid>
If I remove GridViewDefinition with RelationalColumn="SelectedTieredCategoryMix" or GridViewDefinition with RelationalColumn="Tiers" than the export function works. Having both in there at the
same time causes the NullReferenceException. I am using version 15.2.0.40.  The stack trace is attached.


Attachment: stackTrace_2ac17ed4.rar

Muthukumar Kalyanasundaram [Syncfusion]
Replied On May 24, 2017 12:08 AM

Hi John Vong, 
 
Thank you for contacting Syncfusion product. 
 
We have analyzed your query. We were able to reproduce the issue and have logged defect report regarding this. A support incident to track the status of this defect has been created under your account. Please log on to our support website to check for further updates  
 
 
Please let me know if you have any questions.  
 
Regards, 
Muthukumar K 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;