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
Highlight
How a matching cell is drawn.
public XlsxHighlight Highlight { get; }
Property Value
Kind
Which comparison is made.
public XlsxRuleKind Kind { get; }
Property Value
Range
The cells this applies to, such as B2:B99.
public string Range { get; }
Property Value
Text
public string? Text { get; }
Property Value
Value
The number compared against, for the numeric kinds.
public double Value { get; }
Property Value
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
rangestringThe cells this applies to, such as
B2:B99.lowdoubleThe lower bound.
highdoubleThe upper bound.
highlightXlsxHighlightHow a matching cell is drawn.
Returns
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
rangeis null.- ArgumentException
rangeis blank.- ArgumentOutOfRangeException
highis belowlow.
Blank(string, XlsxHighlight)
Highlights empty cells.
public static XlsxRule Blank(string range, XlsxHighlight highlight)
Parameters
rangestringThe cells this applies to, such as
A2:A99.highlightXlsxHighlightHow a matching cell is drawn.
Returns
Exceptions
- ArgumentNullException
rangeis null.- ArgumentException
rangeis blank.
Contains(string, string, XlsxHighlight)
Highlights cells containing text.
public static XlsxRule Contains(string range, string text, XlsxHighlight highlight)
Parameters
rangestringThe cells this applies to, such as
A2:A99.textstringThe text to look for.
highlightXlsxHighlightHow a matching cell is drawn.
Returns
Exceptions
- ArgumentNullException
rangeortextis null.- ArgumentException
rangeis blank.
EqualTo(string, string, XlsxHighlight)
Highlights cells equal to value.
public static XlsxRule EqualTo(string range, string value, XlsxHighlight highlight)
Parameters
rangestringThe cells this applies to, such as
A2:A99.valuestringThe text to compare against.
highlightXlsxHighlightHow a matching cell is drawn.
Returns
Exceptions
- ArgumentNullException
rangeorvalueis null.- ArgumentException
rangeis blank.
GreaterThan(string, double, XlsxHighlight)
Highlights cells whose number is greater than value.
public static XlsxRule GreaterThan(string range, double value, XlsxHighlight highlight)
Parameters
rangestringThe cells this applies to, such as
B2:B99.valuedoubleThe number to compare against.
highlightXlsxHighlightHow a matching cell is drawn.
Returns
Exceptions
- ArgumentNullException
rangeis null.- ArgumentException
rangeis blank.
LessThan(string, double, XlsxHighlight)
Highlights cells whose number is less than value.
public static XlsxRule LessThan(string range, double value, XlsxHighlight highlight)
Parameters
rangestringThe cells this applies to, such as
B2:B99.valuedoubleThe number to compare against.
highlightXlsxHighlightHow a matching cell is drawn.
Returns
Exceptions
- ArgumentNullException
rangeis null.- ArgumentException
rangeis blank.