PivotGridSpreadExport and FileExportMode = FileExportMode.NewSheetInExistingFile

1 Answer 19 Views
PivotGrid and PivotFieldList Spreadsheet
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
Mark asked on 26 Feb 2024, 12:03 PM | edited on 26 Feb 2024, 12:11 PM

I am having issues where data getting exported to an XLSX file where some tabs are not getting the data. FileExportMode is set to FileExportMode.NewSheetInExistingFile and the file is not in use.  The weird part, is I can run the code multiple times and each time, it is different tabs that don't get populated. In the end, I  should end up with 14 tabs and I get those 14 tabs, the only thing that is in the tabs, is the headers.  if I export that data for each tabs individual to their own file, the data is there and exported as expected.  Maybe I am missing something?

Another weird part, is when I watch the file exporting (in window explorer), you can see the file go to 0KB. It is really weird

Here is my export code


         List<Tuple<int, string, bool>> jurisdictionTypes =
            new JurisdictionTypeDA().GetJurisdictionTypeKeyValueList();

         foreach (Tuple<int, string, bool> jurisdictionType in jurisdictionTypes)
         {
            RadPivotGrid tempPivotExportGrid = new RadPivotGrid
            {
               ColumnGrandTotalsPosition = TotalsPos.None,
               ColumnsSubTotalsPosition = TotalsPos.None,
               EmptyValueString = "0",
               RowGrandTotalsPosition = TotalsPos.None,
               RowsSubTotalsPosition = TotalsPos.None
            };

            var exportResults = _apportionmentInfoPivot
               .Where(app => app.JurisdictionTypeKey == jurisdictionType.Item1
               .OrderBy(app => app.PartySort)
               .ThenBy(app => app.LegacyKeyValue)
               .Select(app => new
               {
                  jurisdiction_name = app.JurisdictionName?.Trim() ?? string.Empty,
                  party_name = app.PartyName?.Trim() ?? string.Empty,
                  totalvoters = app.TotalVoters,
                  signaturesneeded = app.SignaturesNeeded
               })
               .ToList();

            tempPivotExportGrid.DataSource = exportResults;
            tempPivotExportGrid.RowGroupDescriptions.Clear();
            tempPivotExportGrid.ColumnGroupDescriptions.Clear();
            tempPivotExportGrid.AggregateDescriptions.Clear();

            // Row Information
            PropertyGroupDescription myRows = new PropertyGroupDescription
            {
               PropertyName = "jurisdiction_name",
               CustomName = "Jurisdiction",
               SortOrder = Telerik.Pivot.Core.SortOrder.None
            };

            tempPivotExportGrid.RowGroupDescriptions.Add(myRows);

            // Column Information
            PropertyGroupDescription myCols = new PropertyGroupDescription
            {
               PropertyName = "party_name",
               CustomName = "Party",
               SortOrder = Telerik.Pivot.Core.SortOrder.None
            };
            tempPivotExportGrid.ColumnGroupDescriptions.Add(myCols);

            // Aggregate Information
            tempPivotExportGrid.AggregateDescriptions.Add(new PropertyAggregateDescription()
            {
               PropertyName = "totalvoters",
               CustomName = "Count",
               AggregateFunction = AggregateFunctions.Sum,
               StringFormat = "#,##0"
            });

            tempPivotExportGrid.AggregateDescriptions.Add(new PropertyAggregateDescription()
            {
               PropertyName = "signaturesneeded",
               CustomName = "Needed",
               AggregateFunction = AggregateFunctions.Sum,
               StringFormat = "#,##0"
            });

            tempPivotExportGrid.AggregatesPosition = PivotAxis.Columns;

            // Combine each result into a new tab
            PivotGridSpreadExport spreadExport = new PivotGridSpreadExport(tempPivotExportGrid)
            {
               SheetName = jurisdictionType.Item2,
               FileExportMode = FileExportMode.NewSheetInExistingFile
            };
            spreadExport.RunExport(myExportFile, new SpreadExportRenderer());

            // Send each result to their own sheet
            PivotGridSpreadExport mySpreadExport2 = new PivotGridSpreadExport(tempPivotExportGrid)
            {
               SheetName = jurisdictionType.Item2,
               FileExportMode = FileExportMode.CreateOrOverrideFile
            };
            string newfile = string.Concat(Path.Combine(Path.GetDirectoryName(myExportFile) ?? string.Empty, Path.GetFileNameWithoutExtension(myExportFile)), "_", jurisdictionType.Item2, Path.GetExtension(myExportFile));
            mySpreadExport2.RunExport(newfile, new SpreadExportRenderer());


         }

Due to the nature of the data, I can't share the results, so I will try to re-create this in a temp project.

 

I have attached a like to a video, you can see at 4 seconds and 9 seconds, the file is emptied (0 KB).

https://app.screencast.com/6SjZNCAoooWUh

TIA for any help here.

 

1 Answer, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 27 Feb 2024, 02:51 PM

Hi Mark,

I appreciate your time in report this.

Probably the case comes from creating the RadPivotGrid control in code. Just for the test, can you execute the same code but for a RadPivotGrid which is already added to a form? Is this behavior still observed? 

To be sure what is going on, it will be better to isolate this behavior in a standalone project so that I can debug it on my side. You can use dummy data for the RadPivotGrid and remove any sensitive information. This way I could have a better look at what is going on.

I am looking forward to your reply.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
PivotGrid and PivotFieldList Spreadsheet
Asked by
Mark
Top achievements
Rank 2
Bronze
Iron
Veteran
Answers by
Dinko | Tech Support Engineer
Telerik team
Share this question
or