# ExcelRangeConditionalFormattingBuilder

Adds conditional formatting rules to an ExcelRange.

Class 

`OfficeIMO.Excel`

**Namespace**

`OfficeIMO.Excel`

**Assembly**

`OfficeIMO.Excel`

**Source revision**

`273d35d5ba8a` with working tree changes

**Source**

[ExcelRangeConditionalFormattingBuilder.cs:30](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L30)

**Modifiers**

sealed

Adds conditional formatting rules to an [ExcelRange](/api/excel/officeimo-excel-excelrange/). Each method adds one native rule and returns it attached to the worksheet; edit it with [ExcelSheet.UpdateConditionalFormattingRule](/api/excel/officeimo-excel-excelsheet/).

## Inheritance

- object
- ExcelRangeConditionalFormattingBuilder

## Remarks

Existing rules are listed, updated, cloned, reordered and removed through the worksheet ([ExcelSheet.GetConditionalFormattingRules](/api/excel/officeimo-excel-excelsheet/), [ExcelSheet.ClearConditionalFormatting](/api/excel/officeimo-excel-excelsheet/)). [ExcelSheet.AddConditionalFormattingRule](/api/excel/officeimo-excel-excelsheet/) adds a rule from the full rule model, including multi-area ranges and Office 2010 extension rules.

## Usage

Explore 1 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

### Returned or exposed by 1

- Method [ExcelRange.ConditionalFormat](/api/excel/officeimo-excel-excelrange/#method-conditionalformat)

Filter members 

Show inherited

## Methods

`public ExcelConditionalFormattingInfo AboveAverage(bool aboveAverage = true, bool equalAverage = false, uint? standardDeviation = null, OfficeColor? fillColor = null, bool stopIfTrue = false)` [#](#method-aboveaverage-boolean-boolean-nullable-system-uint32-nullable-officeimo-officecolor-boolean)

[ExcelRangeConditionalFormattingBuilder.cs:64](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L64)

Adds an above-average or, with aboveAverage false, a below-average rule.

Parameters

**aboveAverage bool = true optional**

True for values above the average; false for values below it.

**equalAverage bool = false optional**

Whether values equal to the average match.

**standardDeviation uint? = null optional**

Optional number of standard deviations from the average.

**fillColor OfficeIMO.OfficeColor? = null optional**

Optional literal or theme-based fill applied when the rule matches.

**stopIfTrue bool = false optional**

Whether lower-priority rules stop when this rule matches.

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo Blanks(bool containsBlanks = true, bool stopIfTrue = false)` [#](#method-blanks-boolean-boolean)

[ExcelRangeConditionalFormattingBuilder.cs:76](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L76)

Adds a blanks or, with containsBlanks false, a non-blanks rule.

Parameters

**containsBlanks bool = true optional**

**stopIfTrue bool = false optional**

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo CellIs(ExcelConditionalFormattingOperator operator, string formula1, string? formula2 = null, OfficeColor? fillColor = null, bool stopIfTrue = false, int? priority = null)` [#](#method-cellis-officeimo-excel-excelconditionalformattingoperator-string-string-nullable-officeimo-officecolor-boolean-nullable-system-int32)

[ExcelRangeConditionalFormattingBuilder.cs:30](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L30)

Adds a cell-value comparison rule, such as greater than, between or equal.

Parameters

**operator OfficeIMO.Excel.ExcelConditionalFormattingOperator required**

Comparison operator.

**formula1 string required**

Primary value or formula.

**formula2 string? = null optional**

Secondary value or formula for Between and NotBetween.

**fillColor OfficeIMO.OfficeColor? = null optional**

Optional literal or theme-based fill applied when the rule matches.

**stopIfTrue bool = false optional**

Whether lower-priority rules stop when this rule matches.

**priority int? = null optional**

Optional explicit rule priority.

Returns

`ExcelConditionalFormattingInfo`

ColorScale 2 overloads

`public ExcelConditionalFormattingInfo ColorScale(OfficeColor startColor, OfficeColor endColor)` [#](#method-colorscale-officeimo-officecolor-officeimo-officecolor)

[ExcelRangeConditionalFormattingBuilder.cs:88](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L88)

Adds a two-color scale from the minimum to the maximum value.

Parameters

**startColor OfficeIMO.OfficeColor required**

**endColor OfficeIMO.OfficeColor required**

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo ColorScale(OfficeColor startColor, OfficeColor midColor, OfficeColor endColor)` [#](#method-colorscale-officeimo-officecolor-officeimo-officecolor-officeimo-officecolor)

[ExcelRangeConditionalFormattingBuilder.cs:92](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L92)

Adds a three-color scale with a 50th-percentile midpoint.

Parameters

**startColor OfficeIMO.OfficeColor required**

**midColor OfficeIMO.OfficeColor required**

**endColor OfficeIMO.OfficeColor required**

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo DataBar(OfficeColor color)` [#](#method-databar-officeimo-officecolor)

[ExcelRangeConditionalFormattingBuilder.cs:96](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L96)

Adds a data bar.

Parameters

**color OfficeIMO.OfficeColor required**

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo DuplicateValues(OfficeColor? fillColor = null)` [#](#method-duplicatevalues-nullable-officeimo-officecolor)

[ExcelRangeConditionalFormattingBuilder.cs:50](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L50)

Adds a duplicate-values rule.

Parameters

**fillColor OfficeIMO.OfficeColor? = null optional**

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo Errors(bool containsErrors = true, bool stopIfTrue = false)` [#](#method-errors-boolean-boolean)

[ExcelRangeConditionalFormattingBuilder.cs:80](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L80)

Adds an errors or, with containsErrors false, a non-errors rule.

Parameters

**containsErrors bool = true optional**

**stopIfTrue bool = false optional**

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo Formula(string formula, OfficeColor? fillColor = null, bool stopIfTrue = false, int? priority = null)` [#](#method-formula-string-nullable-officeimo-officecolor-boolean-nullable-system-int32)

[ExcelRangeConditionalFormattingBuilder.cs:38](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L38)

Adds a formula rule that matches when the formula evaluates to true for the top-left cell.

Parameters

**formula string required**

Formula relative to the top-left cell of the range.

**fillColor OfficeIMO.OfficeColor? = null optional**

Optional literal or theme-based fill applied when the rule matches.

**stopIfTrue bool = false optional**

Whether lower-priority rules stop when this rule matches.

**priority int? = null optional**

Optional explicit rule priority.

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo IconSet(ExcelIconSet iconSet = ThreeTrafficLights1, bool showValue = true, bool reverseIconOrder = false, double[]? percentThresholds = null, double[]? numberThresholds = null)` [#](#method-iconset-officeimo-excel-exceliconset-boolean-boolean-double-double)

[ExcelRangeConditionalFormattingBuilder.cs:106](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L106)

Adds an icon set.

Parameters

**iconSet OfficeIMO.Excel.ExcelIconSet = ThreeTrafficLights1 optional**

Icon set, such as ThreeTrafficLights1, FourArrows or FiveRating.

**showValue bool = true optional**

Whether the cell value is shown next to the icon.

**reverseIconOrder bool = false optional**

Whether the icon order is reversed.

**percentThresholds double[]? = null optional**

Optional percent thresholds (0..100), one per icon.

**numberThresholds double[]? = null optional**

Optional number thresholds, one per icon; used instead of percent thresholds.

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo Text(ExcelConditionalFormatType type, string text, OfficeColor? fillColor = null, bool stopIfTrue = false)` [#](#method-text-officeimo-excel-excelconditionalformattype-string-nullable-officeimo-officecolor-boolean)

[ExcelRangeConditionalFormattingBuilder.cs:46](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L46)

Adds a text rule: contains, does not contain, begins with or ends with.

Parameters

**type OfficeIMO.Excel.ExcelConditionalFormatType required**

ContainsText, NotContainsText, BeginsWith or EndsWith.

**text string required**

Text to match.

**fillColor OfficeIMO.OfficeColor? = null optional**

Optional literal or theme-based fill applied when the rule matches.

**stopIfTrue bool = false optional**

Whether lower-priority rules stop when this rule matches.

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo TimePeriod(ExcelConditionalTimePeriod timePeriod, OfficeColor? fillColor = null, bool stopIfTrue = false)` [#](#method-timeperiod-officeimo-excel-excelconditionaltimeperiod-nullable-officeimo-officecolor-boolean)

[ExcelRangeConditionalFormattingBuilder.cs:84](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L84)

Adds a date rule for a time period such as yesterday, this week or last month.

Parameters

**timePeriod OfficeIMO.Excel.ExcelConditionalTimePeriod required**

**fillColor OfficeIMO.OfficeColor? = null optional**

**stopIfTrue bool = false optional**

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo TopBottom(uint rank, bool bottom = false, bool percent = false, OfficeColor? fillColor = null)` [#](#method-topbottom-uint32-boolean-boolean-nullable-officeimo-officecolor)

[ExcelRangeConditionalFormattingBuilder.cs:72](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L72)

Adds a top or bottom N (or N percent) rule.

Parameters

**rank uint required**

Number of items, or percentage when percent is true.

**bottom bool = false optional**

True for the lowest values; false for the highest.

**percent bool = false optional**

Whether rank is a percentage.

**fillColor OfficeIMO.OfficeColor? = null optional**

Optional literal or theme-based fill applied when the rule matches.

Returns

`ExcelConditionalFormattingInfo`

`public ExcelConditionalFormattingInfo UniqueValues(OfficeColor? fillColor = null)` [#](#method-uniquevalues-nullable-officeimo-officecolor)

[ExcelRangeConditionalFormattingBuilder.cs:54](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Excel/ExcelRangeConditionalFormattingBuilder.cs#L54)

Adds a unique-values rule.

Parameters

**fillColor OfficeIMO.OfficeColor? = null optional**

Returns

`ExcelConditionalFormattingInfo`

## Inherited Methods

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

`public virtual string? ToString()` [#](#method-tostring)

Inherited from object

Returns

`string?`

<!-- PowerForge markdown artifact sha256:9F3E9C1898F722D36A6E0E57DC493700B3E238AEC2B2C7880E9E02CC8F0FF361 -->
