Problem with Aggregated Columns exported to excel

Hi Im getting an error when using an aggragate and exporting it to excel

This is what I get from the OnActionFailed event:

warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
Unhandled exception rendering component: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ProcessSummaryRow(IQueryable items, Boolean totalSummary, Group`1 GroupData)
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ProcessGridContents()
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.IterateElements()
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExportHandler()
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExecuteResult(SfGrid`1 GridModel, Object dataSource)
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExportHelper(SfGrid`1 gridModel, Object dataSource)
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExcelExport(SfGrid`1 GridModel, ExcelExportProperties ExportProperties)
at Syncfusion.Blazor.Grids.SfGrid`1.ExportToExcelAsync(ExcelExportProperties excelExportProperties, Nullable`1 isMultipleExport, Object workbook, Nullable`1 isBlob)
at BlazorGridGroupExample.Components.Pages.Counter.ExportarGrid(MouseEventArgs args) in C:\Temp\BlazorGridGroupExample\Components\Pages\Counter.razor:line 112
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer: Warning: Unhandled exception rendering component: Object reference not set to an instance of an object.










System.NullReferenceException: Object reference not set to an instance of an object. at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ProcessSummaryRow(IQueryable items, Boolean totalSummary, Group`1 GroupData) at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ProcessGridContents() at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.IterateElements() at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExportHandler() at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExecuteResult(SfGrid`1 GridModel, Object dataSource) at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExportHelper(SfGrid`1 gridModel, Object dataSource) at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExcelExport(SfGrid`1 GridModel, ExcelExportProperties ExportProperties) at Syncfusion.Blazor.Grids.SfGrid`1.ExportToExcelAsync(ExcelExportProperties excelExportProperties, Nullable`1 isMultipleExport, Object workbook, Nullable`1 isBlob) at BlazorGridGroupExample.Components.Pages.Counter.ExportarGrid(MouseEventArgs args) in C:\Temp\BlazorGridGroupExample\Components\Pages\Counter.razor:line 112 at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
Unhandled exception in circuit '7sm1nm6i12sQhGkr3erFxANzgoE7xi_hyYUrg2ohSb8'.
System.NullReferenceException: Object reference not set to an instance of an object.
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ProcessSummaryRow(IQueryable items, Boolean totalSummary, Group`1 GroupData)
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ProcessGridContents()
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.IterateElements()
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExportHandler()
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExecuteResult(SfGrid`1 GridModel, Object dataSource)
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExportHelper(SfGrid`1 gridModel, Object dataSource)
at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExcelExport(SfGrid`1 GridModel, ExcelExportProperties ExportProperties)
at Syncfusion.Blazor.Grids.SfGrid`1.ExportToExcelAsync(ExcelExportProperties excelExportProperties, Nullable`1 isMultipleExport, Object workbook, Nullable`1 isBlob)
at BlazorGridGroupExample.Components.Pages.Counter.ExportarGrid(MouseEventArgs args) in C:\Temp\BlazorGridGroupExample\Components\Pages\Counter.razor:line 112
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit '7sm1nm6i12sQhGkr3erFxANzgoE7xi_hyYUrg2ohSb8'. System.NullReferenceException: Object reference not set to an instance of an object. at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ProcessSummaryRow(IQueryable items, Boolean totalSummary, Group`1 GroupData) at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ProcessGridContents() at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.IterateElements() at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExportHandler() at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExecuteResult(SfGrid`1 GridModel, Object dataSource) at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExportHelper(SfGrid`1 gridModel, Object dataSource) at Syncfusion.Blazor.Grids.Internal.GridExcelExport`1.ExcelExport(SfGrid`1 GridModel, ExcelExportProperties ExportProperties) at Syncfusion.Blazor.Grids.SfGrid`1.ExportToExcelAsync(ExcelExportProperties excelExportProperties, Nullable`1 isMultipleExport, Object workbook, Nullable`1 isBlob) at BlazorGridGroupExample.Components.Pages.Counter.ExportarGrid(MouseEventArgs args) in C:\Temp\BlazorGridGroupExample\Components\Pages\Counter.razor:line 112 at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)


I've attached an example, the Grid is on the counter.razor page
If I delete the aggregate from the grid, it works fine



Attachment: BlazorGridGroupExample_aeb32c09.7z

2 Replies

PS Prathap Senthil Syncfusion Team May 30, 2024 05:11 AM UTC

Hi Daniel,



We have confirmed this as an issue and logged the defect report “Error Throwing When Exporting Excel with GroupFooterTemplate Aggregate” for the same and this fix will be included in our upcoming patch release which is expected to be rolled out in our upcoming patch release .

You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.    
  

https://www.syncfusion.com/feedback/58239/error-throwing-when-exporting-excel-with-groupfootertemplate-aggregate

We will get back to you once the release is rolled out. Until then we appreciate your patience.

Regards,
Prathap Senthil



PS Prathap Senthil Syncfusion Team June 25, 2024 07:23 AM UTC

Hi Daniel,


Thanks for the patience,

Regarding the reported issue of Error Throwing When Exporting Excel with GroupFooterTemplate Aggregate, the problem arises because the current Read method only returns the grouping results, excluding aggregate changes. Please refer to the modified code snippet below for clarification

ServiceDataAdaptorComponent.razor.cs

  if (dm.Aggregates != null)

      {

          DataResult.Aggregates = DataUtil.PerformAggregation(DataResult.Result, dm.Aggregates);

      }

 

      if (dm.Group != null && !dm.ServerSideGroup)

   {

      IEnumerable GroupData = Enumerable.Empty<object>();

      foreach (var group in dm.Group)

      {

         var groupData = DataUtil.Group<TModel>(DataResult.Result, group, dm.Aggregates, 0, dm.GroupByFormatter);

         DataResult.Result = groupData;

 

      }

 

      return dm.RequiresCounts ? DataResult : (object)DataResult.Result;

   }

 


While working on this issue, we noticed that Excel Export generates empty cells on the Excel sheet when the grid has template columns. We are pleased to announce that we have included a fix for this in our 26.1.39 release. Please upgrade to the latest version of our Syncfusion NuGet package to resolve the reported issue. You can find the NuGet package for the latest fixes and features below

NuGet : https://www.nuget.org/packages/Syncfusion.Blazor.Grid

Root cause : While calculating the hidden column count we have ensured that the column template should equal to null, since the column template is not null on this case the hidden column count is 0. (After grouping it should have returned 1 on working case)

Action Taken: I have removed the condition that the column template == null so that it satisfied and fixes the above faced issue.

We thank you for your support and appreciate your patience in waiting for this release.

Regards,
Prathap Senthil


Attachment: BlazorGridGroupExample_2fcc650f.zip

Loader.
Up arrow icon