Search in sources :

Example 1 with Beta

use of org.apache.poi.util.Beta in project poi by apache.

the class XSSFPivotCacheDefinition method commit.

@Beta
@Override
protected void commit() throws IOException {
    PackagePart part = getPackagePart();
    OutputStream out = part.getOutputStream();
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    //Sets the pivotCacheDefinition tag
    xmlOptions.setSaveSyntheticDocumentElement(new QName(CTPivotCacheDefinition.type.getName().getNamespaceURI(), "pivotCacheDefinition"));
    ctPivotCacheDefinition.save(out, xmlOptions);
    out.close();
}
Also used : QName(javax.xml.namespace.QName) OutputStream(java.io.OutputStream) XmlOptions(org.apache.xmlbeans.XmlOptions) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) Beta(org.apache.poi.util.Beta)

Example 2 with Beta

use of org.apache.poi.util.Beta in project poi by apache.

the class XSSFPivotCacheDefinition method getPivotArea.

/**
     * Find the 2D base data area for the pivot table, either from its direct reference or named table/range.
     * @return AreaReference representing the current area defined by the pivot table
     * @throws IllegalArgumentException if the ref attribute is not contiguous or the name attribute is not found.
     */
@Beta
public AreaReference getPivotArea(Workbook wb) throws IllegalArgumentException {
    final CTWorksheetSource wsSource = ctPivotCacheDefinition.getCacheSource().getWorksheetSource();
    final String ref = wsSource.getRef();
    final String name = wsSource.getName();
    if (ref == null && name == null) {
        throw new IllegalArgumentException("Pivot cache must reference an area, named range, or table.");
    }
    // this is the XML format, so tell the reference that.
    if (ref != null) {
        return new AreaReference(ref, SpreadsheetVersion.EXCEL2007);
    }
    assert (name != null);
    // named range or table?
    final Name range = wb.getName(name);
    if (range != null) {
        return new AreaReference(range.getRefersToFormula(), SpreadsheetVersion.EXCEL2007);
    }
    // not a named range, check for a table.
    // do this second, as tables are sheet-specific, but named ranges are not, and may not have a sheet name given.
    final XSSFSheet sheet = (XSSFSheet) wb.getSheet(wsSource.getSheet());
    for (XSSFTable table : sheet.getTables()) {
        // TODO: case-sensitive?
        if (name.equals(table.getName())) {
            return new AreaReference(table.getStartCellReference(), table.getEndCellReference());
        }
    }
    throw new IllegalArgumentException("Name '" + name + "' was not found.");
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference) CTWorksheetSource(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheetSource) Name(org.apache.poi.ss.usermodel.Name) QName(javax.xml.namespace.QName) Beta(org.apache.poi.util.Beta)

Example 3 with Beta

use of org.apache.poi.util.Beta in project poi by apache.

the class XSSFPivotTable method commit.

@Beta
@Override
protected void commit() throws IOException {
    XmlOptions xmlOptions = new XmlOptions(DEFAULT_XML_OPTIONS);
    //Sets the pivotTableDefinition tag
    xmlOptions.setSaveSyntheticDocumentElement(new QName(CTPivotTableDefinition.type.getName().getNamespaceURI(), "pivotTableDefinition"));
    PackagePart part = getPackagePart();
    OutputStream out = part.getOutputStream();
    pivotTableDefinition.save(out, xmlOptions);
    out.close();
}
Also used : QName(javax.xml.namespace.QName) XmlOptions(org.apache.xmlbeans.XmlOptions) OutputStream(java.io.OutputStream) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) Beta(org.apache.poi.util.Beta)

Example 4 with Beta

use of org.apache.poi.util.Beta in project poi by apache.

the class XSSFPivotTable method addDataColumn.

/**
     * Add column containing data from the referenced area.
     * @param columnIndex the index of the column containing the data
     * @param isDataField true if the data should be displayed in the pivot table.
     */
@Beta
public void addDataColumn(int columnIndex, boolean isDataField) {
    checkColumnIndex(columnIndex);
    CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
    CTPivotField pivotField = CTPivotField.Factory.newInstance();
    pivotField.setDataField(isDataField);
    pivotField.setShowAll(false);
    pivotFields.setPivotFieldArray(columnIndex, pivotField);
}
Also used : CTPivotField(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField) CTPivotFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields) Beta(org.apache.poi.util.Beta)

Example 5 with Beta

use of org.apache.poi.util.Beta in project poi by apache.

the class XSSFPivotTable method addRowLabel.

/**
     * Add a row label using data from the given column.
     * @param columnIndex the index of the source column to be used as row label.
     * {@code columnIndex} is 0-based indexed and relative to the first column in the source.
     */
@Beta
public void addRowLabel(int columnIndex) {
    checkColumnIndex(columnIndex);
    AreaReference pivotArea = getPivotArea();
    final int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
    CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
    CTPivotField pivotField = CTPivotField.Factory.newInstance();
    CTItems items = pivotField.addNewItems();
    pivotField.setAxis(STAxis.AXIS_ROW);
    pivotField.setShowAll(false);
    for (int i = 0; i <= lastRowIndex; i++) {
        items.addNewItem().setT(STItemType.DEFAULT);
    }
    items.setCount(items.sizeOfItemArray());
    pivotFields.setPivotFieldArray(columnIndex, pivotField);
    CTRowFields rowFields;
    if (pivotTableDefinition.getRowFields() != null) {
        rowFields = pivotTableDefinition.getRowFields();
    } else {
        rowFields = pivotTableDefinition.addNewRowFields();
    }
    rowFields.addNewField().setX(columnIndex);
    rowFields.setCount(rowFields.sizeOfFieldArray());
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference) CTPivotField(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField) CTRowFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRowFields) CTItems(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTItems) CTPivotFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields) 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