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