Как добавить поле столбца в сводную таблицу с помощью Apache POI - PullRequest
0 голосов
/ 27 августа 2018

enter image description here

это моя таблица, и я хочу показывать вот так enter image description here

я даю свой код ниже

  AreaReference a=new org.apache.poi.hssf.util.AreaReference("A1:G1673");

    CellReference b=new CellReference("I5");

    XSSFPivotTable pivotTable = my_sheet.createPivotTable(a,b);
    pivotTable.addRowLabel(2);
    pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 2, "Animated");
    pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 3, "Static");
    pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 5);
    FileOutputStream out=new FileOutputStream("/home/yuktamedia/Downloads/HP/banner1.xlsm");
    wb.write(out);
    out.close();

но мой вывод выглядит так, я не знаю, как добавить поля данных столбца enter image description here

1 Ответ

0 голосов
/ 29 августа 2018
 pivotTable.addRowLabel(2);

        pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 5);
        pivotTable.addDataColumn(5, true);

        pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(1).setAxis(
                org.openxmlformats.schemas.spreadsheetml.x2006.main.STAxis.AXIS_COL);

        pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(1).addNewItems();
        pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(1).getItems().addNewItem().setT(
                org.openxmlformats.schemas.spreadsheetml.x2006.main.STItemType.DEFAULT);

        pivotTable.getCTPivotTableDefinition().addNewColFields().addNewField().setX(1);

отсортировано по этому вопросу

...