Created attachment 33950 [details] pivot table Implementation for XSSFPivotTable.addColumnLabel() method was wrong. Implementation provided for XSSFPivotTable.addColumnLabel() methods is actually the implementation for ValueLabel() methods. If we are creating pivot tables using XSSFPivotTable.addColumnLabel(), the field is adding to the Values position in the excel file.
i have updated code accordingly to fix this issue. i have created a new method XSSFPivotTable.addColumnLabel(int columnIndex) and changed the names of existing XSSFPivotTable.addColumnLabel() methods to XSSFPivotTable.addValueLabel() -------------------------------------------- New method, which i have added --------------------------------------- /** * Add a column label using data from the given column. * @param columnIndex the index of the column to be used as column label. */ @Beta public void addColumnLabel(int columnIndex) { AreaReference pivotArea = getPivotArea(); int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow(); int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol(); if(columnIndex > lastColIndex) { throw new IndexOutOfBoundsException(); } CTPivotFields pivotFields = pivotTableDefinition.getPivotFields(); CTPivotField pivotField = CTPivotField.Factory.newInstance(); CTItems items = pivotField.addNewItems(); pivotField.setAxis(STAxis.AXIS_COL); pivotField.setShowAll(false); for(int i = 0; i <= lastRowIndex; i++) { items.addNewItem().setT(STItemType.DEFAULT); } items.setCount(items.sizeOfItemArray()); pivotFields.setPivotFieldArray(columnIndex, pivotField); CTColFields colFields; if(pivotTableDefinition.getColFields() != null) { colFields = pivotTableDefinition.getColFields(); } else { colFields = pivotTableDefinition.addNewColFields(); } colFields.addNewField().setX(columnIndex); colFields.setCount(colFields.sizeOfFieldArray()); } -------------------------------------------------- Change of previous existing XSSFPivotTable.addColumnLabel methods to XSSFPivotTable.addValueLabel -----------------------------------------------------
@Apache POI developers Please verify it and resolve the ticket
Also please provide the provision to user to apply sorting on row label(s) and/or column label(s)
Thanks for your contribution! Any chance you could also write a unit test for this so that behavior can be verified in our automated builds? Probably the best place to add the unit test would be here: https://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java?view=log
*** Bug 59368 has been marked as a duplicate of this bug. ***