Bug 59705 - Wrong implementation of XSSFPivotTable.addColumnLabel() methods
Summary: Wrong implementation of XSSFPivotTable.addColumnLabel() methods
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.14-FINAL
Hardware: PC All
: P2 blocker (vote)
Target Milestone: ---
Assignee: POI Developers List
: 59368 (view as bug list)
Depends on:
Reported: 2016-06-15 11:45 UTC by Chenna Kesavarao
Modified: 2016-06-19 20:33 UTC (History)
1 user (show)

pivot table (211.55 KB, image/jpeg)
2016-06-15 11:45 UTC, Chenna Kesavarao

Note You need to log in before you can comment on or make changes to this bug.
Description Chenna Kesavarao 2016-06-15 11:45:29 UTC
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.
Comment 1 Chenna Kesavarao 2016-06-15 11:54:36 UTC
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.
    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();

        for(int i = 0; i <= lastRowIndex; i++) {
        pivotFields.setPivotFieldArray(columnIndex, pivotField);

        CTColFields colFields;
        if(pivotTableDefinition.getColFields() != null) {
            colFields = pivotTableDefinition.getColFields();
        } else {
            colFields = pivotTableDefinition.addNewColFields();


Change of previous existing XSSFPivotTable.addColumnLabel methods to XSSFPivotTable.addValueLabel
Comment 2 Chenna Kesavarao 2016-06-15 11:55:48 UTC
@Apache POI developers

Please verify it and resolve the ticket
Comment 3 Chenna Kesavarao 2016-06-17 05:06:57 UTC
Also please provide the provision to user to apply sorting on row label(s) and/or column label(s)
Comment 4 Javen O'Neal 2016-06-17 06:17:04 UTC
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
Comment 5 Javen O'Neal 2016-06-17 10:50:52 UTC
*** Bug 59368 has been marked as a duplicate of this bug. ***