Method Add
- Namespace
- DocWright.Spreadsheet
- Assembly
- DocWright.Spreadsheet.dll
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.
public XlsxDataValidation Add(XlsxCellRange range, XlsxValidationType type, XlsxValidationOperator @operator = XlsxValidationOperator.Between, string? formula1 = null, string? formula2 = null)
Parameters
rangeXlsxCellRangeThe cells the rule covers.
typeXlsxValidationTypeWhat the rule checks. For a list use AddList(XlsxCellRange, params string[]) or AddListFrom(XlsxCellRange, string).
operatorXlsxValidationOperatorformula1stringThe first bound, or the custom formula: a number (
10,2.5; a date as its serial number,46023; a time as a fraction of a day,0.5) or a formula ($Z$1,Data!$B$2,TODAY()), with or without its=. Null for Any.formula2stringThe second bound, for Between and NotBetween only.
Returns
- XlsxDataValidation
The rule.
Exceptions
- ArgumentException
The formulas do not fit the type and the operator, or Excel would refuse one.
- ArgumentOutOfRangeException
The type or the operator is not one of the enumeration's values.
- InvalidOperationException
The sheet is not a worksheet.
- InvalidDocumentException
A part of the workbook is malformed.