2016-04-06 3 views
1

以下のように私はJAVAでExcelシートを作成する必要があります:私は側で複数の列側に行ラベルを作成することはできませんよのApache POI:エクセルピボットテーブル - 行ラベル

enter image description here

(メニューとサブメニューフィルタ)。

サブメニューを別の列に表示する代わりに、メニュー列の下に表示されます。

以下

は私が書いたコードの一部です:

XSSFSheet sheet = my_xlsx_workbook.getSheetAt(0); 
    AreaReference a=new AreaReference("A1:G7"); 
    CellReference b=new CellReference("I5"); 
    XSSFPivotTable pivotTable = sheet.createPivotTable(a,b); 
    pivotTable.addReportFilter(0); 
    pivotTable.addReportFilter(1); 
    pivotTable.addRowLabel(2); 
    pivotTable.addRowLabel(3); 
    pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 4, "Sum"); 

しかし、その誤って以下のように表示行き方:

enter image description here

誰かが私を助けてくださいことはできますか?

+0

ピボットテーブルのオプションで、 "Classic Pivot Table layout"を選択してください – OldUgly

+0

もう少し詳しく教えてください。私はpoi APIの新機能です。 –

+0

Excelで変更する方法を教えてくれました。マクロレコーダーは 'pivotTable.InGridDropZones = True'と' pivotTable.RowAxisLayout xlTabularRow'を表示します。 – OldUgly

答えて

3

フォーマットはXMLなので、必要なものを確認するのは簡単です。 Zip xlsxを開梱し、/xl/pivotTables/pivotTable1.xmlを見てください。

次に:https://poi.apache.org/apidocs/org/apache/poi/xssf/usermodel/XSSFPivotTable.html#getCTPivotTableDefinition%28%29およびhttp://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");