Search in sources :

Example 1 with CTPivotFields

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

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

Example 3 with CTPivotFields

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

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields in project poi by apache.

the class BaseTestXSSFPivotTable method testAddDataColumn.

/**
     * Verify when creating a data column set to a data field, the data field with the corresponding
     * column index will be set to true.
     */
@Test
public void testAddDataColumn() {
    int columnIndex = 0;
    boolean isDataField = true;
    pivotTable.addDataColumn(columnIndex, isDataField);
    CTPivotFields pivotFields = pivotTable.getCTPivotTableDefinition().getPivotFields();
    assertEquals(pivotFields.getPivotFieldArray(columnIndex).getDataField(), isDataField);
}
Also used : CTPivotFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields) Test(org.junit.Test)

Example 5 with CTPivotFields

use of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields in project poi by apache.

the class XSSFPivotTable method addReportFilter.

/**
     * Add filter for the column with the corresponding index and cell value
     * @param columnIndex index of column to filter on
     */
@Beta
public void addReportFilter(int columnIndex) {
    checkColumnIndex(columnIndex);
    AreaReference pivotArea = getPivotArea();
    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_PAGE);
    pivotField.setShowAll(false);
    for (int i = 0; i <= lastRowIndex; i++) {
        items.addNewItem().setT(STItemType.DEFAULT);
    }
    items.setCount(items.sizeOfItemArray());
    pivotFields.setPivotFieldArray(columnIndex, pivotField);
    CTPageFields pageFields;
    if (pivotTableDefinition.getPageFields() != null) {
        pageFields = pivotTableDefinition.getPageFields();
        //Another filter has already been created
        pivotTableDefinition.setMultipleFieldFilters(true);
    } else {
        pageFields = pivotTableDefinition.addNewPageFields();
    }
    CTPageField pageField = pageFields.addNewPageField();
    pageField.setHier(-1);
    pageField.setFld(columnIndex);
    pageFields.setCount(pageFields.sizeOfPageFieldArray());
    pivotTableDefinition.getLocation().setColPageCount(pageFields.getCount());
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference) CTPivotField(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField) CTPageField(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageField) CTPageFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageFields) CTItems(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTItems) CTPivotFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields) Beta(org.apache.poi.util.Beta)

Aggregations

CTPivotFields (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields)5 Beta (org.apache.poi.util.Beta)4 CTPivotField (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField)4 AreaReference (org.apache.poi.ss.util.AreaReference)3 CTItems (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTItems)2 Test (org.junit.Test)1 CTPageField (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageField)1 CTPageFields (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageFields)1 CTRowFields (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRowFields)1