Search in sources :

Example 1 with CTCacheSource

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.");
}
Also used : CTLocation(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTLocation) CTPivotCacheDefinition(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCacheDefinition) AreaReference(org.apache.poi.ss.util.AreaReference) CTCacheSource(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheSource) CellReference(org.apache.poi.ss.util.CellReference) CTWorksheetSource(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheetSource) Beta(org.apache.poi.util.Beta)

Aggregations

AreaReference (org.apache.poi.ss.util.AreaReference)1 CellReference (org.apache.poi.ss.util.CellReference)1 Beta (org.apache.poi.util.Beta)1 CTCacheSource (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCacheSource)1 CTLocation (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTLocation)1 CTPivotCacheDefinition (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotCacheDefinition)1 CTWorksheetSource (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheetSource)1