Hi Team,
Please check the attached pivot TEST.zip (140.1 KB)
Code snippet for creating pivot. Here, i just set the column names to respective fields
private void configurePivot(Header header, int rowCount, int colCount) {
List pivots = header.getPivots();
if (pivots != null) {
for (Pivot pivot : pivots) {
try {
String dataSheetName = “Data”;
String pivotName = pivot.getName();
Worksheet worksheet = (this.workbook.getWorksheets()).add(pivotName);
PivotTableCollection pivotTables = worksheet.getPivotTables();
String sourceData = “’” + dataSheetName + “’!$A$” + (1) + “:” + CellsHelper.cellIndexToName(rowCount, colCount - 1);
int index = pivotTables.add(sourceData, “A3”, pivotName);
PivotTable pivotTable = pivotTables.get(index);
pivotTable.setName(pivotName);
pivotTable.setGridDropZones(true);
pivotTable.setRowGrand(false);
PageField pf = pivot.getPageField();
ColumnField cf = pivot.getColumnField();
RowField rf = pivot.getRowField();
DataField df = pivot.getDataField();
if (pf != null) {
if (pf.getColumns() != null) {
for (String column : pf.getColumns()) {
pivotTable.addFieldToArea(PivotFieldType.PAGE, column);
}
}
}
if (cf != null) {
if (cf.getColumns() != null) {
for (String column : cf.getColumns()) {
pivotTable.addFieldToArea(PivotFieldType.COLUMN, column);
}
}
}
if (rf != null) {
if (rf.getColumns() != null) {
for (String column : rf.getColumns()) {
pivotTable.addFieldToArea(PivotFieldType.ROW, column);
}
}
}
if (df != null) {
if (df.getColumns() != null) {
for (String column : df.getColumns()) {
pivotTable.addFieldToArea(PivotFieldType.DATA, column);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
The pivot is not shown the same way i manually create pivot in MS Excel. Please let me know what am i doing wrong here.
Thanks,
Sukesh