use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheSource 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