DataValidation
- class DataValidation(parent)
Data validation for a range.
Do not construct this class directly; access it through
Range.data_validation.Comparison setters accept these operators:
"between","not_between","equal_to","not_equal_to","greater_than","less_than","greater_than_or_equal", and"less_than_or_equal".Examples
Create a dropdown from literal values:
sheet["A1:A10"].data_validation.set_list(["Open", "Closed"])
Require whole numbers between 1 and 10:
sheet["B1:B10"].data_validation.set_whole_number("between", 1, 10)
Added in version 0.37.5.
- property alert_style: Literal['stop', 'warning', 'information'] | None
The error-alert style.
One of
"stop","warning", or"information".
- property operator: Literal['between', 'not_between', 'equal_to', 'not_equal_to', 'greater_than', 'less_than', 'greater_than_or_equal', 'less_than_or_equal'] | None
The comparison operator, or
Nonefor list and custom rules.
- set_custom(formula)
Create or update a custom-formula validation rule.
The formula must be an A1-style formula starting with
=. Existing prompts and error alerts are preserved.
- set_date(operator, formula1, formula2=None)
Create or update a date validation rule.
Operands may be Python dates, naive datetimes, Excel serial numbers, or Excel formula strings. Existing prompts and error alerts are preserved.
- set_decimal(operator, formula1, formula2=None)
Create or update a decimal validation rule.
formula2is required for"between"and"not_between"and rejected for every other operator. Existing prompts and error alerts are preserved.
- set_list(source, *, in_cell_dropdown=True)
Creates or updates a list validation on the range.
Existing input prompts and error alerts are preserved. The source can be a non-empty sequence of strings, numbers, or booleans, a one-dimensional Range, or a Name that refers to a one-dimensional range in the same workbook.
- set_text_length(operator, formula1, formula2=None)
Create or update a text-length validation rule.
formula2is required for"between"and"not_between"and rejected for every other operator. Existing prompts and error alerts are preserved.
- set_time(operator, formula1, formula2=None)
Create or update a time validation rule.
Operands may be naive Python times, Excel day fractions, or Excel formula strings. Existing prompts and error alerts are preserved.
- set_whole_number(operator, formula1, formula2=None)
Create or update a whole-number validation rule.
formula2is required for"between"and"not_between"and rejected for every other operator. Existing prompts and error alerts are preserved.
- property type: Literal['none', 'whole_number', 'decimal', 'list', 'date', 'time', 'text_length', 'custom', 'inconsistent', 'mixed_criteria', 'unknown']
The normalized validation type for this range.
"none"means that no cell has validation,"mixed_criteria"means that only some cells have validation, and"inconsistent"means that cells have different validation rules. Unsupported native rule types are reported as"unknown".