Search in sources :

Example 1 with CTDataField

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

the class XSSFPivotTable method addDataField.

/**
     * Add data field with data from the given column and specified function.
     * @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 columnIndex the index of the column to be used as column label.
     * @param valueFieldName the name of pivot table value field
     */
@Beta
private void addDataField(DataConsolidateFunction function, int columnIndex, String valueFieldName) {
    checkColumnIndex(columnIndex);
    AreaReference pivotArea = getPivotArea();
    CTDataFields dataFields;
    if (pivotTableDefinition.getDataFields() != null) {
        dataFields = pivotTableDefinition.getDataFields();
    } else {
        dataFields = pivotTableDefinition.addNewDataFields();
    }
    CTDataField dataField = dataFields.addNewDataField();
    dataField.setSubtotal(STDataConsolidateFunction.Enum.forInt(function.getValue()));
    Cell cell = getDataSheet().getRow(pivotArea.getFirstCell().getRow()).getCell(pivotArea.getFirstCell().getCol() + columnIndex);
    cell.setCellType(CellType.STRING);
    dataField.setName(valueFieldName);
    dataField.setFld(columnIndex);
    dataFields.setCount(dataFields.sizeOfDataFieldArray());
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference) CTDataField(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataField) CTDataFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataFields) Cell(org.apache.poi.ss.usermodel.Cell) Beta(org.apache.poi.util.Beta)

Aggregations

Cell (org.apache.poi.ss.usermodel.Cell)1 AreaReference (org.apache.poi.ss.util.AreaReference)1 Beta (org.apache.poi.util.Beta)1 CTDataField (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataField)1 CTDataFields (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataFields)1