Search in sources :

Example 1 with CTPageField

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

the class BaseTestXSSFPivotTable method testAddReportFilter.

/**
     * Verify that it's possible to create a new filter
     */
@Test
public void testAddReportFilter() {
    int columnIndex = 0;
    pivotTable.addReportFilter(columnIndex);
    CTPageFields fields = pivotTable.getCTPivotTableDefinition().getPageFields();
    CTPageField field = fields.getPageFieldArray(0);
    assertEquals(field.getFld(), columnIndex);
    assertEquals(field.getHier(), -1);
    assertEquals(fields.getCount(), 1);
}
Also used : CTPageField(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageField) CTPageFields(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageFields) Test(org.junit.Test)

Example 2 with CTPageField

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

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