Search in sources :

Example 1 with CTColFields

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

the class XSSFPivotTable method addColumnLabel.

/**
     * Add a column label using data from the given column and specified function
     * @param columnIndex the index of the source column to be used as column label.
     * {@code columnIndex} is 0-based indexed and relative to the first column in the source.
     * @param function the function to be used on the data
     * The following functions exists:
     * Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp
     * @param valueFieldName the name of pivot table value field
     */
@Beta
public void addColumnLabel(DataConsolidateFunction function, int columnIndex, String valueFieldName) {
    checkColumnIndex(columnIndex);
    addDataColumn(columnIndex, true);
    addDataField(function, columnIndex, valueFieldName);
    // colfield should be added for the second one.
    if (pivotTableDefinition.getDataFields().getCount() == 2) {
        CTColFields colFields;
        if (pivotTableDefinition.getColFields() != null) {
            colFields = pivotTableDefinition.getColFields();
        } else {
            colFields = pivotTableDefinition.addNewColFields();
        }
        colFields.addNewField().setX(-2);
        colFields.setCount(colFields.sizeOfFieldArray());
    }
}
Also used : CTColFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColFields) Beta(org.apache.poi.util.Beta)

Aggregations

Beta (org.apache.poi.util.Beta)1 CTColFields (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColFields)1