2017-06-21 33 views
0

我有大约1000个具有多列的行,我想创建一个数据透视表。爪哇Poi XSSF - 创建具有多个可扩展列的数据透视表

我的实际结果是: enter image description here

但我希望得到一个数据透视表看起来像这样: enter image description here

我当前的代码:

// ... 
// 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主题,以生成更复杂的数据透视表,但我不知道如何。

有人能帮我解决这个问题吗?

回答

0

找到了解决方案:

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