use of org.apache.poi.util.Beta 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());
}
use of org.apache.poi.util.Beta in project poi by apache.
the class XSSFPivotTable method createDefaultDataColumns.
@Beta
protected void createDefaultDataColumns() {
CTPivotFields pivotFields;
if (pivotTableDefinition.getPivotFields() != null) {
pivotFields = pivotTableDefinition.getPivotFields();
} else {
pivotFields = pivotTableDefinition.addNewPivotFields();
}
AreaReference sourceArea = getPivotArea();
int firstColumn = sourceArea.getFirstCell().getCol();
int lastColumn = sourceArea.getLastCell().getCol();
CTPivotField pivotField;
for (int i = firstColumn; i <= lastColumn; i++) {
pivotField = pivotFields.addNewPivotField();
pivotField.setDataField(false);
pivotField.setShowAll(false);
}
pivotFields.setCount(pivotFields.sizeOfPivotFieldArray());
}
use of org.apache.poi.util.Beta in project poi by apache.
the class XSSFPivotCache method readFrom.
@Beta
protected void readFrom(InputStream is) throws IOException {
try {
XmlOptions options = new XmlOptions(DEFAULT_XML_OPTIONS);
//Removing root element
options.setLoadReplaceDocumentElement(null);
ctPivotCache = CTPivotCache.Factory.parse(is, options);
} catch (XmlException e) {
throw new IOException(e.getLocalizedMessage());
}
}
use of org.apache.poi.util.Beta in project poi by apache.
the class XSSFPivotTable method setDefaultPivotTableDefinition.
/**
* Set default values for the table definition.
*/
@Beta
protected void setDefaultPivotTableDefinition() {
//Not more than one until more created
pivotTableDefinition.setMultipleFieldFilters(false);
//Indentation increment for compact rows
pivotTableDefinition.setIndent(0);
//The pivot version which created the pivot cache set to default value
pivotTableDefinition.setCreatedVersion(CREATED_VERSION);
//Minimun version required to update the pivot cache
pivotTableDefinition.setMinRefreshableVersion(MIN_REFRESHABLE_VERSION);
//Version of the application which "updated the spreadsheet last"
pivotTableDefinition.setUpdatedVersion(UPDATED_VERSION);
//Titles shown at the top of each page when printed
pivotTableDefinition.setItemPrintTitles(true);
//Set autoformat properties
pivotTableDefinition.setUseAutoFormatting(true);
pivotTableDefinition.setApplyNumberFormats(false);
pivotTableDefinition.setApplyWidthHeightFormats(true);
pivotTableDefinition.setApplyAlignmentFormats(false);
pivotTableDefinition.setApplyPatternFormats(false);
pivotTableDefinition.setApplyFontFormats(false);
pivotTableDefinition.setApplyBorderFormats(false);
pivotTableDefinition.setCacheId(pivotCache.getCTPivotCache().getCacheId());
pivotTableDefinition.setName("PivotTable" + pivotTableDefinition.getCacheId());
pivotTableDefinition.setDataCaption("Values");
//Set the default style for the pivot table
CTPivotTableStyle style = pivotTableDefinition.addNewPivotTableStyleInfo();
style.setName("PivotStyleLight16");
style.setShowLastColumn(true);
style.setShowColStripes(false);
style.setShowRowStripes(false);
style.setShowColHeaders(true);
style.setShowRowHeaders(true);
}
use of org.apache.poi.util.Beta in project poi by apache.
the class XSSFPivotTable method createSourceReferences.
/**
* Creates cacheSource and workSheetSource for pivot table and sets the source reference as well assets the location of the pivot table
* @param position Position for pivot table in sheet
* @param sourceSheet Sheet where the source will be collected from
* @param refConfig an configurator that knows how to configure pivot table references
*/
@Beta
protected void createSourceReferences(CellReference position, Sheet sourceSheet, PivotTableReferenceConfigurator refConfig) {
//Get cell one to the right and one down from position, add both to AreaReference and set pivot table location.
AreaReference destination = new AreaReference(position, new CellReference(position.getRow() + 1, position.getCol() + 1));
CTLocation location;
if (pivotTableDefinition.getLocation() == null) {
location = pivotTableDefinition.addNewLocation();
location.setFirstDataCol(1);
location.setFirstDataRow(1);
location.setFirstHeaderRow(1);
} else {
location = pivotTableDefinition.getLocation();
}
location.setRef(destination.formatAsString());
pivotTableDefinition.setLocation(location);
//Set source for the pivot table
CTPivotCacheDefinition cacheDef = getPivotCacheDefinition().getCTPivotCacheDefinition();
CTCacheSource cacheSource = cacheDef.addNewCacheSource();
cacheSource.setType(STSourceType.WORKSHEET);
CTWorksheetSource worksheetSource = cacheSource.addNewWorksheetSource();
worksheetSource.setSheet(sourceSheet.getSheetName());
setDataSheet(sourceSheet);
refConfig.configureReference(worksheetSource);
if (worksheetSource.getName() == null && worksheetSource.getRef() == null)
throw new IllegalArgumentException("Pivot table source area reference or name must be specified.");
}
Aggregations