Table of Contents

Class XlsxDataValidations

Namespace
DocWright.Spreadsheet
Assembly
DocWright.Spreadsheet.dll

The data validation rules of one sheet of an opened workbook (Phase 201): listed as the file holds them, added, changed and removed as Excel's Data Validation does, and written the way Excel writes its own.

public sealed class XlsxDataValidations : IReadOnlyList<XlsxDataValidation>, IReadOnlyCollection<XlsxDataValidation>, IEnumerable<XlsxDataValidation>, IEnumerable
Inheritance
XlsxDataValidations
Implements
Inherited Members

Remarks

Measured with Excel (tools/Probe-ExcelValidations.ps1): a rule whose formula names another sheet is stored in the sheet's x14 extension, every other rule in its dataValidations; this list holds both, those of the main element first. A rule added over cells that have one replaces it there: the old rule keeps the rest of its cells, the part to the left, to the right, above and below the new range, and goes when nothing is left. Where a file gives a cell two rules, the first one listed is the one Excel uses.

Edits are held in memory and written into the sheet's part when anything next reads it (an insert, a sort, a copy) or the workbook is saved: adding a rule to every row of a long sheet costs one write of the part.

Properties

Count

Gets the number of rules.

this[int]

Gets a rule by its place in the list.

Methods

Add(XlsxCellRange, XlsxValidationType, XlsxValidationOperator, string?, string?)

Adds a rule over a range, as Excel's Data Validation does: the cells' old rules give those cells up. The rule allows blank cells and shows its input and error messages, as a new rule in Excel does; its properties change the rest.

AddList(XlsxCellRange, params string[])

Adds a list rule whose items the rule itself holds (Excel's Source box with North,South,East), with the in-cell dropdown.

AddListFrom(XlsxCellRange, string)

Adds a list rule whose items are the values of a range or a name, with the in-cell dropdown.

For(int, int)

Returns the rule that covers a cell: the first the file lists, as Excel takes it.

For(string)

Returns the rule that covers a cell: the first the file lists, as Excel takes it.

GetEnumerator()

Returns the rules, those of the main element first, each block in the order the file lists them.

Remove(XlsxCellRange)

Removes the validation of a range, as Excel's Clear All in Data Validation does: every rule gives up the cells in the range, and a rule left with none goes. The cells keep their values.

Remove(XlsxDataValidation)

Removes one rule, with all its cells.

Validate(int, int, XlsxCellValue)

Returns whether the rule over a cell would accept a value. See Validate(string, XlsxCellValue).

Validate(string, XlsxCellValue)

Returns whether the rule over a cell would accept a value, as Excel judges a value typed into it (measured with Excel's own Validation.Value): true when no rule covers the cell.