Free Support Forum - aspose.com

Calling pivotTable.CalculateData() causes a crash when there is 1 data column

Creating a pivot table with one data field and calling CalculateData() on it causes a crash. You can use the following sample code to demonstrate.



void Main()
{
    var workbook = new Workbook();
    
    var sourceSheet = CreateSourceSheet( workbook );
    CreatePivotSheet( 
        workbook: workbook, 
        sourceData: string.Format( 
            "='{0}'!A1:{1}", 
            sourceSheet.Name, 
            CellsHelper.CellIndexToName( row: sourceSheet.Cells.MaxDataRow, column: sourceSheet.Cells.MaxDataColumn ) ) );
    
    workbook.Save( @"C:\tmp\asposecells_calculatedfield.xlsx" );
    Process.Start( @"C:\tmp\asposecells_calculatedfield.xlsx" );
}

private Worksheet CreateSourceSheet( Workbook workbook )
{
    var sheet = workbook.Worksheets[0];
    sheet.Name = "Source Sheet";

	sheet.Cells[0, 0].Value = "Currency";
    sheet.Cells[1, 0].Value = "USD";
    sheet.Cells[2, 0].Value = "USD";
    sheet.Cells[3, 0].Value = "USD";
    sheet.Cells[4, 0].Value = "USD";
       
    sheet.Cells[0, 1].Value = "Cats";
    sheet.Cells[1, 1].Value = 100;
    sheet.Cells[2, 1].Value = 200;
    sheet.Cells[3, 1].Value = 25;
    sheet.Cells[4, 1].Value = 50;
	
	sheet.Cells[0, 2].Value = "Dogs";
    sheet.Cells[1, 2].Value = 100;
    sheet.Cells[2, 2].Value = 200;
    sheet.Cells[3, 2].Value = 25;
    sheet.Cells[4, 2].Value = 50;
    
    return sheet;
}

private Worksheet CreatePivotSheet( Workbook workbook, string sourceData )
{
    var pivotSheet = workbook.Worksheets.Add( "Pivot Sheet" );
	Console.Out.WriteLine(sourceData);
    var pivotTableIndex = pivotSheet.PivotTables.Add( 
        sourceData,
        "A1",
        "PivotTable1" );
    var pivotTable = pivotSheet.PivotTables[ pivotTableIndex ];
	pivotTable.ManualUpdate = false;
    pivotTable.IsAutoFormat = true; // Auto format columns?
    pivotTable.ShowInCompactForm();
	pivotTable.MissingItemsLimit = PivotMissingItemLimitType.None;
    
	//if the type is anything but PivotFieldType.Data it works
    pivotTable.AddFieldToArea( PivotFieldType.Data, "Cats" );
	//when you add multiple fields, it works
	//pivotTable.AddFieldToArea( PivotFieldType.Data, "Dogs" );
	pivotTable.CalculateData();

    
    return pivotSheet;
}
This is happening with version 8.9.2.0

Hi,


Thanks for your posting and using Aspose.Cells.

We were able to observe this issue and logged it in our database for investigation. We will look into it and fix this issue. Once the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSNET-44814.

Hi,

Thanks for using Aspose.Cells.

This is to inform you that we have fixed your issue CELLSNET-44814 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

Hi,

Thanks for using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v16.10.2.0 and let us know your feedback.

The issues you have found earlier (filed as CELLSNET-44814) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.