use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDataFields 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());
}
Aggregations