1

I want to generate a pivot table and all of the columns should have the filter like shown in the picture.

Is there anyway to activate it in poi for every col except last one because it is just a sum col?

Ma current code to generate the pivot table:

int firstRow = sheet.getFirstRowNum() + firstDataRow;
int lastRow = sheet.getLastRowNum();
int firstCol = sheet.getRow(0).getFirstCellNum();
int lastCol = sheet.getRow(firstRow).getLastCellNum();

CellReference topLeft = new CellReference(firstRow, firstCol);
CellReference botRight = new CellReference(lastRow, lastCol - 1);

AreaReference areaRef = new AreaReference(topLeft, botRight);

XSSFPivotTable pivotTable = pivotSheet.createPivotTable(areaRef,
        new CellReference(firstRow, firstCol), sheet);

pivotTable.addRowLabel(lastCol - 1); // Month
pivotTable.addRowLabel(6); // User
pivotTable.addRowLabel(lastCol - 2); // State
pivotTable.addColumnLabel(DataConsolidateFunction.COUNT, 0,
        resBundle.getString("WG_NM")); // count

CTPivotFields pFields = 
pivotTable.getCTPivotTableDefinition().getPivotFields();
pFields.getPivotFieldArray(lastCol - 1).setOutline(false);
pFields.getPivotFieldArray(6).setOutline(false);
pFields.getPivotFieldArray(lastCol - 2).setOutline(false);

enter image description here

ninjaxelite
  • 1,139
  • 2
  • 20
  • 43
  • Best way to do this is with a template -> [Like here](https://stackoverflow.com/questions/31976127/accessing-field-settings-of-pivot-table-using-apache-poi/) – ninjaxelite Apr 10 '18 at 12:21

0 Answers0