且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Apache POI:Excel 数据透视表 - 行标签

更新时间:2023-08-24 21:57:52

因为格式是 XML,所以很容易检查需要什么.解压 Zip xlsx 并查看 /xl/pivotTables/pivotTable1.xml.

Since the format is XML it is easy to check what is needed. Unpack the Zip xlsx and look in the /xl/pivotTables/pivotTable1.xml.

然后:https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFPivotTable.html#getCTPivotTableDefinition%28%29http://grepcode.com/file/repo1.maven.org/maven2/org.apache.poi/ooxml-schemas/1.1/org/openxmlformats/schemas/spreadsheetml/x2006/main/CTPivotTableDefinition.java.

    AreaReference a=new AreaReference(new CellReference("A1"), new CellReference("E7"));
    CellReference b=new CellReference("I5");
    XSSFPivotTable pivotTable = sheet.createPivotTable(a,b);
    pivotTable.addReportFilter(0);
    pivotTable.addReportFilter(1);
    pivotTable.addRowLabel(2);

pivotTable.getCTPivotTableDefinition().getPivotFields().getPivotFieldArray(2).setOutline(false);

    pivotTable.addRowLabel(3);
    pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 4, "Sum");