For performance reasons, this class keeps a cache of all previously retrieved DataValidation instances.
Be sure to call clearAllCachedValues() if any workbook validation definitions are
added, modified, or deleted.
Changing cell values should be fine, as long as the corresponding WorkbookEvaluator#clearAllCachedResultValues()
is called as well.
| Modifier and Type | Class and Description |
|---|---|
| public static class | DataValidationEvaluator.
This class organizes and encapsulates all the pieces of information related to a single data validation configuration for a single cell. |
| public static enum | DataValidationEvaluator.
Not calling it OperatorType to avoid confusion for now with DataValidationConstraint.OperatorType. |
| public static enum | DataValidationEvaluator.
Not calling it ValidationType to avoid confusion for now with DataValidationConstraint.ValidationType. |
| Modifier and Type | Field and Description |
|---|---|
| private final Map | validations
Expensive to compute, so cache them as they are retrieved. |
| private final Workbook | |
| private final WorkbookEvaluator |
| Access | Constructor and Description |
|---|---|
| public | DataValidationEvaluator(Workbook
the workbook this operates on wb, WorkbookEvaluatorProvider provider for formula evaluation provider)Use the same formula evaluation context used for other operations, so cell value changes are automatically noticed |
| Modifier and Type | Method and Description |
|---|---|
| public void | clearAllCachedValues()
Call this whenever validation structures change, so future results stay in sync with the Workbook state. |
| public DataValidationEvaluator. | Returns: the DataValidationContext applicable to the given cell, or null if no validation appliesreference to check cell)Finds and returns the |
| public DataValidation | Returns: the DataValidation applicable to the given cell, or null if no validation appliesreference to check - use this in case the cell does not actually exist yet cell)Finds and returns the |
| private List | Returns: TheDataValidations for the sheetThe sheet)Sheet to load validations for.Lazy load validations by sheet, since reading the CT* types is expensive |
| public List | getValidationValuesForCell(CellReference
reference to check - use this in case the cell does not actually exist yet cell)If |
| protected static List | getValidationValuesForConstraint(DataValidationEvaluator.
static so enums can reference it without creating a whole instance |
| protected WorkbookEvaluator | |
| public static boolean | |
| public boolean | Returns: true if the cell has no validation or the cell value passes the defined validation, false if it failsThe reference of the cell to evaluate cellRef)Use the validation returned by |
| validations | back to summary |
|---|---|
| private final Map<String, List<? extends DataValidation>> validations Expensive to compute, so cache them as they are retrieved. Sheets don't implement equals, and since its an interface, there's no guarantee instances won't be recreated on the fly by some implementation. So we use sheet name. | |
| workbook | back to summary |
|---|---|
| private final Workbook workbook | |
| workbookEvaluator | back to summary |
|---|---|
| private final WorkbookEvaluator workbookEvaluator | |
| DataValidationEvaluator | back to summary |
|---|---|
| public DataValidationEvaluator(Workbook wb, WorkbookEvaluatorProvider provider) Use the same formula evaluation context used for other operations, so cell value changes are automatically noticed
| |
| clearAllCachedValues | back to summary |
|---|---|
| public void clearAllCachedValues() Call this whenever validation structures change, so future results stay in sync with the Workbook state. | |
| getValidationContextForCell | back to summary |
|---|---|
| public DataValidationEvaluator. Finds and returns the
| |
| getValidationForCell | back to summary |
|---|---|
| public DataValidation getValidationForCell(CellReference cell) Finds and returns the
| |
| getValidations | back to summary |
|---|---|
| private List Lazy load validations by sheet, since reading the CT* types is expensive
| |
| getValidationValuesForCell | back to summary |
|---|---|
| public List If For all other validation types, or no validation at all, this method returns null. This method could throw an exception if the validation type is not LIST, but since this method is mostly useful in UI contexts, null seems the easier path.
| |
| getValidationValuesForConstraint | back to summary |
|---|---|
| protected static List static so enums can reference it without creating a whole instance | |
| getWorkbookEvaluator | back to summary |
|---|---|
protected WorkbookEvaluator getWorkbookEvaluator()
| |
| isType | back to summary |
|---|---|
| public static boolean isType(Cell cell, CellType type) Note that this assumes the cell cached value is up to date and in sync with data edits | |
| isValidCell | back to summary |
|---|---|
| public boolean isValidCell(CellReference cellRef) Use the validation returned by Note that to properly apply some validations, care must be taken to offset the base validation formula by the relative position of the current cell, or the wrong value is checked.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final DataValidation | |
| private final DataValidationEvaluator | |
| private final CellRangeAddressBase | |
| private final CellReference |
| Access | Constructor and Description |
|---|---|
| public | DataValidationContext(DataValidation dv, DataValidationEvaluator dve, CellRangeAddressBase region, CellReference target)
Populate the context with the necessary values. |
| Modifier and Type | Method and Description |
|---|---|
| public DataValidationEvaluator | |
| public String | |
| public String | |
| public int | |
| public int | |
| public int | |
| public CellRangeAddressBase | |
| public int | |
| public CellReference | |
| public DataValidation |
| dv | back to summary |
|---|---|
| private final DataValidation dv | |
| dve | back to summary |
|---|---|
| private final DataValidationEvaluator dve | |
| region | back to summary |
|---|---|
| private final CellRangeAddressBase region | |
| target | back to summary |
|---|---|
| private final CellReference target | |
| DataValidationContext | back to summary |
|---|---|
| public DataValidationContext(DataValidation dv, DataValidationEvaluator dve, CellRangeAddressBase region, CellReference target) Populate the context with the necessary values. | |
| getEvaluator | back to summary |
|---|---|
public DataValidationEvaluator getEvaluator()
| |
| getFormula1 | back to summary |
|---|---|
| public String getFormula1() | |
| getFormula2 | back to summary |
|---|---|
| public String getFormula2() | |
| getOffsetColumns | back to summary |
|---|---|
| public int getOffsetColumns() | |
| getOffsetRows | back to summary |
|---|---|
| public int getOffsetRows() | |
| getOperator | back to summary |
|---|---|
| public int getOperator() | |
| getRegion | back to summary |
|---|---|
public CellRangeAddressBase getRegion()
| |
| getSheetIndex | back to summary |
|---|---|
| public int getSheetIndex() | |
| getTarget | back to summary |
|---|---|
public CellReference getTarget()
| |
| getValidation | back to summary |
|---|---|
public DataValidation getValidation()
| |
| Modifier and Type | Field and Description |
|---|---|
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public abstract boolean | Returns: true if the comparison is validwon't be null, assumption is previous checks handled that cellValue, Double if null, value assumed invalid, anything passes, per Excel behavior v1, Double null if not needed. If null when needed, assume anything passes, per Excel behavior v2)Evaluates comparison using operator instance rules |
| public static DataValidationEvaluator. | |
| public static DataValidationEvaluator. |
| BETWEEN | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| EQUAL | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| GREATER_OR_EQUAL | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| GREATER_THAN | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| IGNORED | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| LESS_OR_EQUAL | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| LESS_THAN | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| NOT_BETWEEN | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| NOT_EQUAL | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| OperatorEnum | back to summary |
|---|---|
| private OperatorEnum() | |
| isValid | back to summary |
|---|---|
| public abstract boolean isValid(Double cellValue, Double v1, Double v2) Evaluates comparison using operator instance rules
| |
| valueOf | back to summary |
|---|---|
| public static DataValidationEvaluator. | |
| values | back to summary |
|---|---|
| public static DataValidationEvaluator. | |
| Modifier and Type | Field and Description |
|---|---|
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. | |
| public static final DataValidationEvaluator. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| private Double | Returns: numeric value or null if not defined or the formula evaluates to an empty/missing cell.The text of the formula or a numeric value formula, DataValidationEvaluator.The contextDataValidationContext which is used for evaluationEvaluate a numeric formula value as either a constant or numeric expression. |
| public static boolean | Returns: true if validation passesCell to check validity of cell, DataValidationEvaluator.The Data Validation to check against contextValidates against the type defined in context, as an index of the enum values array. |
| protected boolean | Returns: if the cell is a valid numeric cell for the validation or notUses the cell value, which may be the cached formula result value. |
| protected boolean | isValidNumericValue(Double value, final DataValidationEvaluator.
Is the number a valid option for the validation? |
| public boolean | |
| public static DataValidationEvaluator. | |
| public static DataValidationEvaluator. |
| ANY | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| DATE | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| DECIMAL | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| FORMULA | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| INTEGER | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| LIST | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| TEXT_LENGTH | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| TIME | back to summary |
|---|---|
| public static final DataValidationEvaluator. | |
| ValidationEnum | back to summary |
|---|---|
| private ValidationEnum() | |
| evalOrConstant | back to summary |
|---|---|
| private Double evalOrConstant(String formula, DataValidationEvaluator. Evaluate a numeric formula value as either a constant or numeric expression. Note that Excel treats validations with constraint formulas that evaluate to null as valid, but evaluations in error or non-numeric are marked invalid.
| |
| isValid | back to summary |
|---|---|
| public static boolean isValid(Cell cell, DataValidationEvaluator. Validates against the type defined in context, as an index of the enum values array.
| |
| isValidNumericCell | back to summary |
|---|---|
| protected boolean isValidNumericCell(Cell cell, DataValidationEvaluator. Uses the cell value, which may be the cached formula result value. We won't re-evaluate cells here. This validation would be after the cell value was updated externally. Excel allows invalid values through methods like copy/paste, and only validates them when the user interactively edits the cell.
| |
| isValidNumericValue | back to summary |
|---|---|
| protected boolean isValidNumericValue(Double value, final DataValidationEvaluator. Is the number a valid option for the validation? | |
| isValidValue | back to summary |
|---|---|
| public boolean isValidValue(Cell cell, DataValidationEvaluator. | |
| valueOf | back to summary |
|---|---|
| public static DataValidationEvaluator. | |
| values | back to summary |
|---|---|
| public static DataValidationEvaluator. | |