Search in sources :

Example 1 with CTRowFields

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRowFields in project poi by apache.

the class XSSFPivotTable method addRowLabel.

/**
     * Add a row label using data from the given column.
     * @param columnIndex the index of the source column to be used as row label.
     * {@code columnIndex} is 0-based indexed and relative to the first column in the source.
     */
@Beta
public void addRowLabel(int columnIndex) {
    checkColumnIndex(columnIndex);
    AreaReference pivotArea = getPivotArea();
    final int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
    CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
    CTPivotField pivotField = CTPivotField.Factory.newInstance();
    CTItems items = pivotField.addNewItems();
    pivotField.setAxis(STAxis.AXIS_ROW);
    pivotField.setShowAll(false);
    for (int i = 0; i <= lastRowIndex; i++) {
        items.addNewItem().setT(STItemType.DEFAULT);
    }
    items.setCount(items.sizeOfItemArray());
    pivotFields.setPivotFieldArray(columnIndex, pivotField);
    CTRowFields rowFields;
    if (pivotTableDefinition.getRowFields() != null) {
        rowFields = pivotTableDefinition.getRowFields();
    } else {
        rowFields = pivotTableDefinition.addNewRowFields();
    }
    rowFields.addNewField().setX(columnIndex);
    rowFields.setCount(rowFields.sizeOfFieldArray());
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference) CTPivotField(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField) CTRowFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRowFields) CTItems(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTItems) CTPivotFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields) Beta(org.apache.poi.util.Beta)

Aggregations

AreaReference (org.apache.poi.ss.util.AreaReference)1 Beta (org.apache.poi.util.Beta)1 CTItems (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTItems)1 CTPivotField (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField)1 CTPivotFields (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields)1 CTRowFields (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRowFields)1