Table of Contents

Class XlsxRule

Namespace
DocToolkit
Assembly
DocToolkit.Xlsx.dll

A conditional format: highlight the cells in a range that meet a condition.

public sealed class XlsxRule
Inheritance
XlsxRule
Inherited Members

Remarks

Six conditions, all measured to survive a save and reload. The library beneath offers nine; EqualOrGreaterThan, EqualOrLessThan and NotEquals are omitted because each is expressible with what is here, and every extra factory is a member to test, document and support forever. They persist, so adding one later is a smaller decision than removing it.

Properties

High

The upper bound, for Between.

public double High { get; }

Property Value

double

Highlight

How a matching cell is drawn.

public XlsxHighlight Highlight { get; }

Property Value

XlsxHighlight

Kind

Which comparison is made.

public XlsxRuleKind Kind { get; }

Property Value

XlsxRuleKind

Range

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

public string Range { get; }

Property Value

string

Text

The text compared against, for EqualTo and Contains. Null for every other kind.

public string? Text { get; }

Property Value

string

Value

The number compared against, for the numeric kinds.

public double Value { get; }

Property Value

double

Methods

Between(string, double, double, XlsxHighlight)

Highlights cells whose number falls between two bounds, inclusive.

public static XlsxRule Between(string range, double low, double high, XlsxHighlight highlight)

Parameters

range string

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

low double

The lower bound.

high double

The upper bound.

highlight XlsxHighlight

How a matching cell is drawn.

Returns

XlsxRule

Remarks

high must not be below low: inverted bounds describe an empty range, so the rule would never fire and the sheet would look formatted while nothing was highlighted.

Exceptions

ArgumentNullException

range is null.

ArgumentException

range is blank.

ArgumentOutOfRangeException

high is below low.

Blank(string, XlsxHighlight)

Highlights empty cells.

public static XlsxRule Blank(string range, XlsxHighlight highlight)

Parameters

range string

The cells this applies to, such as A2:A99.

highlight XlsxHighlight

How a matching cell is drawn.

Returns

XlsxRule

Exceptions

ArgumentNullException

range is null.

ArgumentException

range is blank.

Contains(string, string, XlsxHighlight)

Highlights cells containing text.

public static XlsxRule Contains(string range, string text, XlsxHighlight highlight)

Parameters

range string

The cells this applies to, such as A2:A99.

text string

The text to look for.

highlight XlsxHighlight

How a matching cell is drawn.

Returns

XlsxRule

Exceptions

ArgumentNullException

range or text is null.

ArgumentException

range is blank.

EqualTo(string, string, XlsxHighlight)

Highlights cells equal to value.

public static XlsxRule EqualTo(string range, string value, XlsxHighlight highlight)

Parameters

range string

The cells this applies to, such as A2:A99.

value string

The text to compare against.

highlight XlsxHighlight

How a matching cell is drawn.

Returns

XlsxRule

Exceptions

ArgumentNullException

range or value is null.

ArgumentException

range is blank.

GreaterThan(string, double, XlsxHighlight)

Highlights cells whose number is greater than value.

public static XlsxRule GreaterThan(string range, double value, XlsxHighlight highlight)

Parameters

range string

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

value double

The number to compare against.

highlight XlsxHighlight

How a matching cell is drawn.

Returns

XlsxRule

Exceptions

ArgumentNullException

range is null.

ArgumentException

range is blank.

LessThan(string, double, XlsxHighlight)

Highlights cells whose number is less than value.

public static XlsxRule LessThan(string range, double value, XlsxHighlight highlight)

Parameters

range string

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

value double

The number to compare against.

highlight XlsxHighlight

How a matching cell is drawn.

Returns

XlsxRule

Exceptions

ArgumentNullException

range is null.

ArgumentException

range is blank.