I am using aspose-cells-17.9 java version. I am trying to create a pivot table from the raw data sample shown below.
Affiliate ImpressionClicks
abc 1000 2000
and so on.
If i try to create pivot table with the following code
PivotTable pivotTable = pivotTables.get(index);
// Unshowing grand totals for rows.
pivotTable.setRowGrand(true);
// Dragging the first field to the row area.
pivotTable.addFieldToArea(PivotFieldType.ROW, 0);
// Dragging the second field to the column area.
pivotTable.addFieldToArea(PivotFieldType.COLUMN, 1);
// Dragging the third field to the data area.
pivotTable.addFieldToArea(PivotFieldType.DATA, 2);
I am getting the following output as selected values.
But what I am expecting is as follows
Any help would be appreciated.
Please see the following sample code, its comments and screenshot. As you can see in screenshot, the output Excel file has the pivot table as per your needs. Please remember Σ-values field is represented by PivotTable.getDataField() and this is the change I have made in your code.
Java
PivotTable pivotTable = pivotTables.get(index);
// Unshowing grand totals for rows.
pivotTable.setRowGrand(true);
// Dragging the first field to the row area.
pivotTable.addFieldToArea(PivotFieldType.ROW, 0);
// Dragging the second field to the data area.
pivotTable.addFieldToArea(PivotFieldType.DATA, 1);
// Dragging the third field to the data area.
pivotTable.addFieldToArea(PivotFieldType.DATA, 2);
// Dragging the Σ-values field to the column area.
pivotTable.addFieldToArea(PivotFieldType.COLUMN, pivotTable.getDataField());
Note: I am working as Developer Evangelist at Aspose