Java Poi XSSF - 创建具有多个可扩展列的枢轴 table

Java Poi XSSF - create pivot table with multiple expandable columns

我有大约 1000 行多列,我想从中创建一个数据透视表 table。

我的实际结果是:

但我想得到一个如下所示的枢轴 table:

我当前的代码:

// ... 
// fill sheet with data 
// ...

// create 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);

XSSFPivotTable pivotTable = pivotSheet.createPivotTable(
        new AreaReference(topLeft, botRight), new CellReference(firstRow, lastCol), sheet);

pivotTable.addRowLabel(lastCol - 1); // month
pivotTable.addRowLabel(6); // car
pivotTable.addRowLabel(lastCol - 2); // state
pivotTable.addColumnLabel(DataConsolidateFunction.COUNT, 0, 
        resourceBundle.getString("Count"));

我什至不知道如何命名不同的结果。 我想我需要更深入地研究 poi 主题以生成更复杂的枢轴 table 但我不知道如何。

谁能帮我解决这个问题?

找到解决方案:

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