Table of Contents

Class XlsxValidation

Namespace
DocToolkit
Assembly
DocToolkit.Xlsx.dll

A data validation: what a person may type into a range of cells once the workbook is open.

public sealed class XlsxValidation
Inheritance
XlsxValidation
Inherited Members

Remarks

This is the half of a generated workbook that survives a human editing it. Five kinds, all measured to persist through a save and reload.

Properties

Kind

What the cells are restricted to.

public XlsxValidationKind Kind { get; }

Property Value

XlsxValidationKind

Max

The upper bound, for the numeric and text-length kinds.

public double Max { get; }

Property Value

double

MaxDate

The latest date, for Date.

public DateTime MaxDate { get; }

Property Value

DateTime

Min

The lower bound, for the numeric and text-length kinds.

public double Min { get; }

Property Value

double

MinDate

The earliest date, for Date.

public DateTime MinDate { get; }

Property Value

DateTime

Options

The permitted options, for List. Empty for every other kind.

public IReadOnlyList<string> Options { get; }

Property Value

IReadOnlyList<string>

Range

The cells this applies to, such as B2:B99.

public string Range { get; }

Property Value

string

Methods

DateBetween(string, DateTime, DateTime)

Restricts the range to a date between two bounds, inclusive.

public static XlsxValidation DateBetween(string range, DateTime min, DateTime max)

Parameters

range string

The cells this applies to.

min DateTime

The earliest permitted date.

max DateTime

The latest permitted date.

Returns

XlsxValidation

Exceptions

ArgumentNullException

range is null.

ArgumentException

range is blank.

ArgumentOutOfRangeException

max is before min.

DecimalBetween(string, double, double)

Restricts the range to a decimal number between two bounds, inclusive.

public static XlsxValidation DecimalBetween(string range, double min, double max)

Parameters

range string

The cells this applies to.

min double

The lowest permitted value.

max double

The highest permitted value.

Returns

XlsxValidation

Exceptions

ArgumentNullException

range is null.

ArgumentException

range is blank.

ArgumentOutOfRangeException

max is below min.

OneOf(string, params string[])

Restricts the range to one of a fixed list of options.

public static XlsxValidation OneOf(string range, params string[] options)

Parameters

range string

The cells this applies to.

options string[]

The permitted values. At least one is required.

Returns

XlsxValidation

Remarks

An option may not contain a comma or a double quote, and may not be blank. The list is written into the file as one quoted, comma-joined formula, so a comma inside an option would silently become two options and a quote would produce a malformed formula — measured. This type's premise is a vocabulary that can be enumerated and guaranteed, and accepting input it cannot faithfully encode is the wrong failure.

Exceptions

ArgumentNullException

range or options is null.

ArgumentException

range is blank, options is empty, or an option is null, blank, or contains a comma or a double quote.

TextLengthBetween(string, int, int)

Restricts the range to text whose length is between two bounds, inclusive.

public static XlsxValidation TextLengthBetween(string range, int min, int max)

Parameters

range string

The cells this applies to.

min int

The shortest permitted length.

max int

The longest permitted length.

Returns

XlsxValidation

Exceptions

ArgumentNullException

range is null.

ArgumentException

range is blank.

ArgumentOutOfRangeException

max is below min.

WholeNumberBetween(string, int, int)

Restricts the range to a whole number between two bounds, inclusive.

public static XlsxValidation WholeNumberBetween(string range, int min, int max)

Parameters

range string

The cells this applies to.

min int

The lowest permitted value.

max int

The highest permitted value.

Returns

XlsxValidation

Remarks

int rather than long because that is what the file format takes — a wider parameter would only move the truncation somewhere the caller cannot see it.

Exceptions

ArgumentNullException

range is null.

ArgumentException

range is blank.

ArgumentOutOfRangeException

max is below min.