Validity

LibreOffice's Data ▸ Validity limits what a cell accepts: a list of values (shown as a drop-down), a whole number or decimal within limits, a date, a time, a text length, or a formula. A file must be open for writing; getDataValidation also works on files opened for reading.

using OpenDocumentSpreadsheets
using OpenDocumentSpreadsheets: getDataValidation

ods = newods("Orders")
sh = ods["Orders"]
sh["A1:C1"] = ["Colour" "Quantity" "Size"]
lists = addsheet!(ods, "Lists")
lists["A1:A3"] = ["Small"; "Medium"; "Large";;]

addDataValidation(sh, "A2:A20"; type = :list, values = ["Red", "Green", "Blue"])
addDataValidation(sh, "B2:B20"; type = :whole, operator = :between, formula1 = 1, formula2 = 10,
                  error = "A whole number from 1 to 10", errorStyle = :stop)
addDataValidation(sh, "C2:C20"; type = :list, formula1 = "Lists.\$A\$1:\$A\$3", sortEntries = true)
sh["A2"] = "Green"
getDataValidation(sh, "B5")

LibreOffice shows a list rule's values as a drop-down on the cell:

The Orders sheet in LibreOffice with the cursor on A2, which holds Green, and its drop-down open listing Red, Green and Blue

A cell has one rule: a new rule replaces the rule of the cells it covers, and deleteDataValidation removes one:

deleteDataValidation(sh, "C2:C20")

The Validity dialog and the keywords

Each setting of LibreOffice's Data ▸ Validity dialog is a keyword of addDataValidation:

Validity dialogKeyword
Criteria ▸ Allow: All values, Integer, Decimal, Date, Time, Text length, Customtype = :any, :whole, :decimal, :date, :time, :textLength, :custom
Allow: List, with its entriestype = :list, values = ["Red", "Green"]
Allow: Cell rangetype = :list, formula1 = "Lists.$A$1:$A$3"
Data: equal, less than, greater than, less than or equal, greater than or equal to, not equaloperator = :equal, :lessThan, :greaterThan, :lessThanOrEqual, :greaterThanOrEqual, :notEqual
Data: valid range, invalid rangeoperator = :between (the default), :notBetween
Minimum (or the one value), Maximumformula1, formula2
Custom's formulaformula1 = "=ISNUMBER(B2)"
Allow empty cellsallowBlank (true by default)
Show selection list (a list)dropdown
Sort entries ascending (a list)sortEntries
Case sensitivecaseSensitive
Input Help: Show input help when cell is selected, Title, Input helpshowInputMessage, promptTitle, prompt
Error Alert: Handle invalid values, Action, Title, Error messageshowErrorMessage, errorStyle = :stop, :warning or :information, errorTitle, error

formula1 and formula2 take numbers, dates and times as they are, or a reference or formula in the notation LibreOffice's formula bar shows.