2017-06-21 41 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);