Hello,
I am getting the below error when creating pivot table. Please help.
Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Aspose.Cells.CellsException: This pivot field has more unique items than can be used in a pivot table.
This is my code:
//Getting the pivottables collection in the sheet
Aspose.Cells.Pivot.
PivotTableCollection pivotTables = sheet2.PivotTables;
//Adding a PivotTable to the worksheet
int index = pivotTables.Add(targetRange.Name, "A8", "PivotTable1");
//Accessing the instance of the newly added PivotTable
Aspose.Cells.Pivot.
PivotTable pivotTable = pivotTables[index];
//Showing the grand totals
pivotTable.RowGrand =
true;
pivotTable.ColumnGrand =
true;
//Setting the PivotTable report is automatically formatted
pivotTable.IsAutoFormat =
true;
//Setting the PivotTable autoformat type.
pivotTable.AutoFormatType = Aspose.Cells.Pivot.
PivotTableAutoFormatType.Report6;
//Draging the first field to the row area.
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Row, 7);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Row, 4);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Row, 3);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Row, 5);
//Draging the fourth field to the column area.
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Column, 13);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Column, 14);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Column, 15);
//Getting the pivottables collection in the sheet
Aspose.Cells.Pivot.
PivotTableCollection pivotTables = sheet2.PivotTables;
//Adding a PivotTable to the worksheet
int index = pivotTables.Add(targetRange.Name, "A8", "PivotTable1");
//Accessing the instance of the newly added PivotTable
Aspose.Cells.Pivot.
PivotTable pivotTable = pivotTables[index];
//Showing the grand totals
pivotTable.RowGrand =
true;
pivotTable.ColumnGrand =
true;
//Setting the PivotTable report is automatically formatted
pivotTable.IsAutoFormat =
true;
//Setting the PivotTable autoformat type.
pivotTable.AutoFormatType = Aspose.Cells.Pivot.
PivotTableAutoFormatType.Report6;
//Draging the first field to the row area.
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Row, 7);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Row, 4);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Row, 3);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Row, 5);
//Draging the fourth field to the column area.
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Column, 13);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Column, 14);
pivotTable.AddFieldToArea(Aspose.Cells.Pivot.
PivotFieldType.Column, 15);
Thanks,
Jyotshna