Class DataValidationEvaluator

    • Constructor Detail

      • DataValidationEvaluator

        public DataValidationEvaluator​(Workbook wb,
                                       WorkbookEvaluatorProvider provider)
        Use the same formula evaluation context used for other operations, so cell value changes are automatically noticed
        wb - the workbook this operates on
        provider - provider for formula evaluation
    • Method Detail

      • clearAllCachedValues

        public void clearAllCachedValues()
        Call this whenever validation structures change, so future results stay in sync with the Workbook state.
      • getValidationForCell

        public DataValidation getValidationForCell​(CellReference cell)
        Finds and returns the DataValidation for the cell, if there is one. Lookup is based on the first match from 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.
        cell - reference to check - use this in case the cell does not actually exist yet
        the DataValidation applicable to the given cell, or null if no validation applies
      • isValidCell

        public boolean isValidCell​(CellReference cellRef)
        Use the validation returned by getValidationForCell(CellReference) if you want the error display details. This is the validation checked by this method, which attempts to replicate Excel's data validation rules.

        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.

        cellRef - The reference of the cell to evaluate
        true if the cell has no validation or the cell value passes the defined validation, false if it fails
      • isType

        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
        cell - The Cell to check.
        type - The CellType to check for.
        true if the cell or cached cell formula result type match the given type