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