Search in sources :

Example 31 with AreaReference

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);
    }
}
Also used : AreaReference(org.apache.poi.ss.util.AreaReference)

Example 32 with AreaReference

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

AreaReference (org.apache.poi.ss.util.AreaReference)32 CellReference (org.apache.poi.ss.util.CellReference)19 Test (org.junit.Test)10 Beta (org.apache.poi.util.Beta)7 SXSSFWorkbook (org.apache.poi.xssf.streaming.SXSSFWorkbook)6 Cell (org.apache.poi.ss.usermodel.Cell)4 Row (org.apache.poi.ss.usermodel.Row)4 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)3 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)3 FileOutputStream (java.io.FileOutputStream)2 MemFuncPtg (org.apache.poi.ss.formula.ptg.MemFuncPtg)2 Workbook (org.apache.poi.ss.usermodel.Workbook)2 CTPivotField (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotField)2 CTPivotFields (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields)2 CTWorksheetSource (org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheetSource)2 InputStream (java.io.InputStream)1 QName (javax.xml.namespace.QName)1 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)1 NameRecord (org.apache.poi.hssf.record.NameRecord)1 HSSFEvaluationWorkbook (org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook)1