use of org.apache.poi.ss.util.AreaReference in project poi by apache.
the class XSSFPivotTable method checkColumnIndex.
/**
* Verify column index (relative to first column in pivot area) is within the
* pivot area
*
* @param columnIndex
* @throws IndexOutOfBoundsException
*/
private void checkColumnIndex(int columnIndex) throws IndexOutOfBoundsException {
AreaReference pivotArea = getPivotArea();
int size = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol() + 1;
if (columnIndex < 0 || columnIndex >= size) {
throw new IndexOutOfBoundsException("Column Index: " + columnIndex + ", Size: " + size);
}
}
use of org.apache.poi.ss.util.AreaReference 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