Java Poi XSSF-创建具有多个可扩展列的透视表
我有大约1000行和多列,我想用它们创建一个透视表 我的实际结果是: 但我想得到一个透视表,如下所示: 我当前的代码:Java Poi XSSF-创建具有多个可扩展列的透视表,java,excel,apache-poi,xssf,Java,Excel,Apache Poi,Xssf,我有大约1000行和多列,我想用它们创建一个透视表 我的实际结果是: 但我想得到一个透视表,如下所示: 我当前的代码: // ... // fill sheet with data // ... // create Pivot table int firstRow = sheet.getFirstRowNum() + firstDataRow; int lastRow = sheet.getLastRowNum(); int firstCol = sheet.getRow(0).get
// ...
// 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主题,以生成更复杂的透视表,但我不知道如何生成
有人能帮我解决这个问题吗?找到了解决方案:
CTPivotFields pFields = pivotTable.getCTPivotTableDefinition().getPivotFields();
pFields.getPivotFieldArray(lastCol - 1).setOutline(false);
pFields.getPivotFieldArray(6).setOutline(false);
pFields.getPivotFieldArray(lastCol - 2).setOutline(false);