Search in sources :

Example 6 with Beta

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());
}
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)

Example 7 with Beta

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());
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference) CTPivotField(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField) CTPivotFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields) Beta(org.apache.poi.util.Beta)

Example 8 with Beta

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());
    }
}
Also used : XmlException(org.apache.xmlbeans.XmlException) XmlOptions(org.apache.xmlbeans.XmlOptions) IOException(java.io.IOException) Beta(org.apache.poi.util.Beta)

Example 9 with Beta

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);
}
Also used : CTPivotTableStyle(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotTableStyle) Beta(org.apache.poi.util.Beta)

Example 10 with Beta

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.");
}
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

Beta (org.apache.poi.util.Beta)21 AreaReference (org.apache.poi.ss.util.AreaReference)7 XmlOptions (org.apache.xmlbeans.XmlOptions)7 IOException (java.io.IOException)4 QName (javax.xml.namespace.QName)4 PackagePart (org.apache.poi.openxml4j.opc.PackagePart)4 XmlException (org.apache.xmlbeans.XmlException)4 CTPivotField (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField)4 CTPivotFields (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields)4 OutputStream (java.io.OutputStream)3 Cell (org.apache.poi.ss.usermodel.Cell)3 Row (org.apache.poi.ss.usermodel.Row)2 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)2 CellReference (org.apache.poi.ss.util.CellReference)2 CTItems (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTItems)2 CTWorksheetSource (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheetSource)2 HashSet (java.util.HashSet)1 FormulaShifter (org.apache.poi.ss.formula.FormulaShifter)1 CellCopyPolicy (org.apache.poi.ss.usermodel.CellCopyPolicy)1 Name (org.apache.poi.ss.usermodel.Name)1