Apache POI XSSF – 如何在数据透视表中添加“两级”列标签

我从文件Test.xlsx使用Apache POI 3.14生成PIVOT表
注意:addColLabel方法来自JensGabe的链接。 根据链接,此方法(XSSFPivotTable.addRowLabel的稍微修改版本)添加了“常规”透视列标签。

public static void main(String[] args){ Connection conn = null; try { //Input file XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream("Excel_pivot_template_2.xlsx")); XSSFSheet sheet = wb.getSheetAt(0); XSSFPivotTable pivotTable = sheet.createPivotTable(new AreaReference(new CellReference("A3"), new CellReference("E11")), new CellReference("I3")); //second column from the input file pivotTable.addRowLabel(1); addColLabel(pivotTable, 0); pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 2); FileOutputStream fileOut = new FileOutputStream("pivot_output.xlsx"); wb.write(fileOut); fileOut.close(); wb.close(); System.out.println("********* Complete *********** "); } 

从程序input和输出: 从程序输入和输出

预期产出: 预期产出

任何帮助,非常感激。我还没有任何成功呢。