Search in sources :

Example 1 with CellRangeAddressList

use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.

the class DataValidationEvaluator method getValidationContextForCell.

/**
     * Finds and returns the {@link DataValidationContext} for the cell, if there is
     * one. Lookup is based on the first match from
     * {@link DataValidation#getRegions()} for the cell's sheet. DataValidation
     * regions must be in the same sheet as the DataValidation. Allowed values
     * expressions may reference other sheets, however.
     * 
     * @param cell reference to check
     * @return the DataValidationContext applicable to the given cell, or null if no
     *         validation applies
     */
public DataValidationContext getValidationContextForCell(CellReference cell) {
    final Sheet sheet = workbook.getSheet(cell.getSheetName());
    if (sheet == null)
        return null;
    final List<? extends DataValidation> dataValidations = getValidations(sheet);
    if (dataValidations == null)
        return null;
    for (DataValidation dv : dataValidations) {
        final CellRangeAddressList regions = dv.getRegions();
        if (regions == null)
            return null;
        // current implementation can't return null
        for (CellRangeAddressBase range : regions.getCellRangeAddresses()) {
            if (range.isInRange(cell)) {
                return new DataValidationContext(dv, this, range, cell);
            }
        }
    }
    return null;
}
Also used : CellRangeAddressBase(org.apache.poi.ss.util.CellRangeAddressBase) CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) Sheet(org.apache.poi.ss.usermodel.Sheet) DataValidation(org.apache.poi.ss.usermodel.DataValidation)

Example 2 with CellRangeAddressList

use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.

the class TestXSSFDataValidation method createValidation.

private XSSFDataValidation createValidation(XSSFSheet sheet) {
    //create the cell that will have the validation applied
    final Row row = sheet.createRow(0);
    row.createCell(0);
    DataValidationHelper dataValidationHelper = sheet.getDataValidationHelper();
    DataValidationConstraint constraint = dataValidationHelper.createCustomConstraint("true");
    final XSSFDataValidation validation = (XSSFDataValidation) dataValidationHelper.createValidation(constraint, new CellRangeAddressList(0, 0, 0, 0));
    return validation;
}
Also used : DataValidationConstraint(org.apache.poi.ss.usermodel.DataValidationConstraint) CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) Row(org.apache.poi.ss.usermodel.Row) DataValidationHelper(org.apache.poi.ss.usermodel.DataValidationHelper)

Example 3 with CellRangeAddressList

use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.

the class CFHeaderBase method createEmpty.

protected void createEmpty() {
    field_3_enclosing_cell_range = new CellRangeAddress(0, 0, 0, 0);
    field_4_cell_ranges = new CellRangeAddressList();
}
Also used : CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 4 with CellRangeAddressList

use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.

the class CFHeaderBase method read.

protected void read(RecordInputStream in) {
    field_1_numcf = in.readShort();
    field_2_need_recalculation_and_id = in.readShort();
    field_3_enclosing_cell_range = new CellRangeAddress(in);
    field_4_cell_ranges = new CellRangeAddressList(in);
}
Also used : CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress)

Example 5 with CellRangeAddressList

use of org.apache.poi.ss.util.CellRangeAddressList in project poi by apache.

the class TestPLVRecord method testPLVRecord.

public void testPLVRecord() throws Exception {
    InputStream is = HSSFTestDataSamples.openSampleFileStream(XLS_FILENAME);
    HSSFWorkbook workbook = new HSSFWorkbook(is);
    CellRangeAddressList cellRange = new CellRangeAddressList(0, 0, 1, 1);
    DataValidationConstraint constraint = DVConstraint.createFormulaListConstraint(DV_DEFINITION);
    HSSFDataValidation dataValidation = new HSSFDataValidation(cellRange, constraint);
    // This used to throw an error before
    try {
        workbook.getSheet(SHEET_NAME).addValidationData(dataValidation);
    } catch (IllegalStateException ex) {
        throw new AssertionFailedError("Identified bug 53972, PLV record breaks addDataValidation()");
    }
}
Also used : HSSFDataValidation(org.apache.poi.hssf.usermodel.HSSFDataValidation) InputStream(java.io.InputStream) DataValidationConstraint(org.apache.poi.ss.usermodel.DataValidationConstraint) CellRangeAddressList(org.apache.poi.ss.util.CellRangeAddressList) AssertionFailedError(junit.framework.AssertionFailedError) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Aggregations

CellRangeAddressList (org.apache.poi.ss.util.CellRangeAddressList)27 Test (org.junit.Test)16 DataValidationConstraint (org.apache.poi.ss.usermodel.DataValidationConstraint)14 DataValidation (org.apache.poi.ss.usermodel.DataValidation)13 DataValidationHelper (org.apache.poi.ss.usermodel.DataValidationHelper)13 BaseTestDataValidation (org.apache.poi.ss.usermodel.BaseTestDataValidation)12 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)6 BigDecimal (java.math.BigDecimal)4 Sheet (org.apache.poi.ss.usermodel.Sheet)4 ArrayList (java.util.ArrayList)3 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Row (org.apache.poi.ss.usermodel.Row)2 CellReference (org.apache.poi.ss.util.CellReference)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 AssertionFailedError (junit.framework.AssertionFailedError)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1