I am currently using the Apache POI 3.12 for adding pivot table. Here my sample.xlsx file :
Now I using the following code for creating the pivot table for the above data.
File excel = new File("sample.xlsx");
FileInputStream fis = new FileInputStream(excel);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet = wb.getSheetAt(0);
XSSFPivotTable pivotTable = sheet.createPivotTable(new AreaReference("A3:C7"), new CellReference("E3"));
pivotTable.addRowLabel(0);
pivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
pivotTable.addDataColumn(1, true);
pivotTable.addReportFilter(2);
FileOutputStream fileOut = new FileOutputStream("output.xlsx");
wb.write(fileOut);
fileOut.close();
wb.close();
My output.xlsx file have the following pivot table :
When I am going to edit the pivot table in excel it adding the year column in page fields not column fields. Actually I need the following result :
I can't add multiple column label from single column value. Could you please help me? Thanks in advance


