Class ExcelValidation

java.lang.Object
io.github.dornol.excelkit.excel.ExcelValidation

public class ExcelValidation extends Object
Advanced data validation configuration for Excel columns.

Supports integer, decimal, text length, date, and custom formula validations. Use the static factory methods to create validation instances.


 writer.column("Age", Person::getAge, c -> c
     .validation(ExcelValidation.integerBetween(1, 150)));
 
Since:
0.7.0
  • Method Details

    • integerBetween

      public static ExcelValidation integerBetween(int min, int max)
      Creates a validation that requires an integer between min and max (inclusive).
      Parameters:
      min - minimum value (inclusive)
      max - maximum value (inclusive)
      Returns:
      the validation instance
    • integerGreaterThan

      public static ExcelValidation integerGreaterThan(int min)
      Creates a validation that requires an integer greater than the given value.
      Parameters:
      min - the minimum threshold (exclusive)
      Returns:
      the validation instance
    • integerLessThan

      public static ExcelValidation integerLessThan(int max)
      Creates a validation that requires an integer less than the given value.
      Parameters:
      max - the maximum threshold (exclusive)
      Returns:
      the validation instance
    • decimalBetween

      public static ExcelValidation decimalBetween(double min, double max)
      Creates a validation that requires a decimal between min and max (inclusive).
      Parameters:
      min - minimum value (inclusive)
      max - maximum value (inclusive)
      Returns:
      the validation instance
    • textLength

      public static ExcelValidation textLength(int min, int max)
      Creates a validation that restricts text length between min and max (inclusive).
      Parameters:
      min - minimum text length (inclusive)
      max - maximum text length (inclusive)
      Returns:
      the validation instance
    • dateRange

      public static ExcelValidation dateRange(LocalDate start, LocalDate end)
      Creates a validation that restricts dates between start and end (inclusive).
      Parameters:
      start - the earliest allowed date
      end - the latest allowed date
      Returns:
      the validation instance
    • listFromRange

      public static ExcelValidation listFromRange(String range)
      Creates a list validation that references a cell range for dropdown options.

      Use this when dropdown options come from another sheet or cell range instead of inline string arrays.

      Parameters:
      range - the cell range reference (e.g., "Sheet2!$A$1:$A$10")
      Returns:
      the validation instance
    • formula

      public static ExcelValidation formula(String formula)
      Creates a validation using a custom Excel formula.
      Parameters:
      formula - the Excel formula
      Returns:
      the validation instance
    • errorTitle

      public ExcelValidation errorTitle(String errorTitle)
      Sets the error dialog title.
      Parameters:
      errorTitle - the error dialog title
      Returns:
      this instance for chaining
    • errorMessage

      public ExcelValidation errorMessage(String errorMessage)
      Sets the error dialog message.
      Parameters:
      errorMessage - the error message text
      Returns:
      this instance for chaining
    • showError

      public ExcelValidation showError(boolean showError)
      Sets whether to show the error dialog when validation fails.
      Parameters:
      showError - whether to show the error dialog
      Returns:
      this instance for chaining