<!-- Generated by tools/SharpCell.Docs from the XML documentation comments. Do not edit; run the tool with 'generate'. -->

# ConditionalFormat

```csharp
public sealed class ConditionalFormat
```

Namespace `SharpCell` · package `SharpCell`

A conditional format: which cells of its ranges it formats, and how. Make one with a factory such as [ConditionalFormat.CellValue](SharpCell.ConditionalFormat.md#cellvalue-conditionaloperator-string-conditionalstyle-string), [ConditionalFormat.Expression](SharpCell.ConditionalFormat.md#expression-string-conditionalstyle) or [ConditionalFormat.Top](SharpCell.ConditionalFormat.md#top-int-conditionalstyle-bool), change it with `with` (`rule with { StopIfTrue = true }`), and add it with [Worksheet.AddConditionalFormat](SharpCell.Worksheet.md#addconditionalformat-string-conditionalformat). SharpCell works out which cells a rule applies to ([Cell.ConditionalFormats](SharpCell.Cell.md#conditionalformats)) and how a cell then looks ([Cell.DisplayStyle](SharpCell.Cell.md#displaystyle)).

## Properties

<a id="formula1"></a>
### Formula1

```csharp
public string? Formula1 { get; }
```

The formula of a [ConditionalFormatType.CellValue](SharpCell.ConditionalFormatType.md#cellvalue) or [ConditionalFormatType.Expression](SharpCell.ConditionalFormatType.md#expression) rule, starting with `=`, relative to the first cell of the rule's first range; null for other rules.

<a id="formula2"></a>
### Formula2

```csharp
public string? Formula2 { get; }
```

The second formula of a between rule; null for others.

<a id="operator"></a>
### Operator

```csharp
public ConditionalOperator Operator { get; }
```

How a [ConditionalFormatType.CellValue](SharpCell.ConditionalFormatType.md#cellvalue) rule compares; [ConditionalOperator.Between](SharpCell.ConditionalOperator.md#between) for other rules.

<a id="orequal"></a>
### OrEqual

```csharp
public bool OrEqual { get; }
```

Whether an above or below average rule also formats values equal to the average.

<a id="percent"></a>
### Percent

```csharp
public bool Percent { get; }
```

Whether [ConditionalFormat.Rank](SharpCell.ConditionalFormat.md#rank) is a percentage.

<a id="period"></a>
### Period

```csharp
public TimePeriod Period { get; }
```

The period of a [ConditionalFormatType.TimePeriod](SharpCell.ConditionalFormatType.md#timeperiod) rule.

<a id="rank"></a>
### Rank

```csharp
public int Rank { get; }
```

How many values (or what percentage of them) a top or bottom rule formats; 0 for others.

<a id="standarddeviations"></a>
### StandardDeviations

```csharp
public int StandardDeviations { get; }
```

How many standard deviations above or below the average a value must be; 0 for the average itself.

<a id="stopiftrue"></a>
### StopIfTrue

```csharp
public bool StopIfTrue { get; init; }
```

Whether lower rules are skipped for a cell this rule applies to, as Excel's Stop If True does.

<a id="style"></a>
### Style

```csharp
public ConditionalStyle? Style { get; init; }
```

How matching cells look; null for colour scales, data bars and icon sets, which colour each cell themselves.

<a id="text"></a>
### Text

```csharp
public string? Text { get; }
```

The text a text rule looks for; null for others.

<a id="type"></a>
### Type

```csharp
public ConditionalFormatType Type { get; }
```

What the rule looks at.

## Methods

<a id="aboveaverage-conditionalstyle-bool-int"></a>
### AboveAverage(ConditionalStyle, bool, int)

```csharp
public static ConditionalFormat AboveAverage(ConditionalStyle style, bool orEqual = false, int standardDeviations = 0)
```

Numbers above the average of the ranges, or by `standardDeviations` standard deviations above it.

**Exceptions**

- `ArgumentOutOfRangeException`: The standard deviations are outside 0 to 3, as in Excel.

<a id="beginswith-string-conditionalstyle"></a>
### BeginsWith(string, ConditionalStyle)

```csharp
public static ConditionalFormat BeginsWith(string text, ConditionalStyle style)
```

Cells whose text begins with `text`, ignoring case.

**Exceptions**

- `ArgumentException`: The text is empty.

<a id="belowaverage-conditionalstyle-bool-int"></a>
### BelowAverage(ConditionalStyle, bool, int)

```csharp
public static ConditionalFormat BelowAverage(ConditionalStyle style, bool orEqual = false, int standardDeviations = 0)
```

Numbers below the average of the ranges, or by `standardDeviations` standard deviations below it.

**Exceptions**

- `ArgumentOutOfRangeException`: The standard deviations are outside 0 to 3, as in Excel.

<a id="blanks-conditionalstyle"></a>
### Blanks(ConditionalStyle)

```csharp
public static ConditionalFormat Blanks(ConditionalStyle style)
```

Empty cells and cells holding only spaces.

<a id="bottom-int-conditionalstyle-bool"></a>
### Bottom(int, ConditionalStyle, bool)

```csharp
public static ConditionalFormat Bottom(int rank, ConditionalStyle style, bool percent = false)
```

The `rank` lowest numbers of the ranges, or the lowest `rank` percent of them.

**Exceptions**

- `ArgumentOutOfRangeException`: The rank is outside 1 to 1000, or a percentage outside 1 to 100.

<a id="cellvalue-conditionaloperator-string-conditionalstyle-string"></a>
### CellValue(ConditionalOperator, string, ConditionalStyle, string)

```csharp
public static ConditionalFormat CellValue(ConditionalOperator comparison, string formula1, ConditionalStyle style, string? formula2 = null)
```

Cells whose value compares with the formulas, such as greater than `=100` or between `=$B$1` and `=$B$2`.

**Parameters**

- `comparison`: How the value compares.
- `formula1`: The formula compared with, starting with `=`, relative to the range's first cell.
- `style`: How matching cells look.
- `formula2`: The second formula, for [ConditionalOperator.Between](SharpCell.ConditionalOperator.md#between) and [ConditionalOperator.NotBetween](SharpCell.ConditionalOperator.md#notbetween).

**Exceptions**

- `ArgumentException`: A formula is missing or empty, or a second formula is given to a comparison that takes one.

<a id="containstext-string-conditionalstyle"></a>
### ContainsText(string, ConditionalStyle)

```csharp
public static ConditionalFormat ContainsText(string text, ConditionalStyle style)
```

Cells whose text contains `text`, ignoring case.

**Exceptions**

- `ArgumentException`: The text is empty.

<a id="dateoccurring-timeperiod-conditionalstyle"></a>
### DateOccurring(TimePeriod, ConditionalStyle)

```csharp
public static ConditionalFormat DateOccurring(TimePeriod period, ConditionalStyle style)
```

Dates in a period around today, as Excel's A Date Occurring.

**Exceptions**

- `ArgumentOutOfRangeException`: The period is not a defined value.

<a id="duplicatevalues-conditionalstyle"></a>
### DuplicateValues(ConditionalStyle)

```csharp
public static ConditionalFormat DuplicateValues(ConditionalStyle style)
```

Values that appear more than once in the ranges; text ignoring case.

<a id="endswith-string-conditionalstyle"></a>
### EndsWith(string, ConditionalStyle)

```csharp
public static ConditionalFormat EndsWith(string text, ConditionalStyle style)
```

Cells whose text ends with `text`, ignoring case.

**Exceptions**

- `ArgumentException`: The text is empty.

<a id="equals-conditionalformat"></a>
### Equals(ConditionalFormat)

```csharp
public bool Equals(ConditionalFormat? other)
```

Whether the other rule has the same settings and style; texts compared ordinally.

<a id="errors-conditionalstyle"></a>
### Errors(ConditionalStyle)

```csharp
public static ConditionalFormat Errors(ConditionalStyle style)
```

Cells holding an error.

<a id="expression-string-conditionalstyle"></a>
### Expression(string, ConditionalStyle)

```csharp
public static ConditionalFormat Expression(string formula, ConditionalStyle style)
```

Cells for which a formula is true, such as `=$C2>$B2`, written for the range's first cell.

**Parameters**

- `formula`: The formula, starting with `=`.
- `style`: How matching cells look.

**Exceptions**

- `ArgumentException`: The formula is empty.

<a id="gethashcode"></a>
### GetHashCode()

```csharp
public override int GetHashCode()
```

A hash code consistent with [ConditionalFormat.Equals](SharpCell.ConditionalFormat.md#equals-conditionalformat).

<a id="noblanks-conditionalstyle"></a>
### NoBlanks(ConditionalStyle)

```csharp
public static ConditionalFormat NoBlanks(ConditionalStyle style)
```

Cells that are not blank.

<a id="noerrors-conditionalstyle"></a>
### NoErrors(ConditionalStyle)

```csharp
public static ConditionalFormat NoErrors(ConditionalStyle style)
```

Cells not holding an error.

<a id="notcontainstext-string-conditionalstyle"></a>
### NotContainsText(string, ConditionalStyle)

```csharp
public static ConditionalFormat NotContainsText(string text, ConditionalStyle style)
```

Cells whose text does not contain `text`.

**Exceptions**

- `ArgumentException`: The text is empty.

<a id="tostring"></a>
### ToString()

```csharp
public override string ToString()
```

The type, and the formula or text when the rule has one.

<a id="top-int-conditionalstyle-bool"></a>
### Top(int, ConditionalStyle, bool)

```csharp
public static ConditionalFormat Top(int rank, ConditionalStyle style, bool percent = false)
```

The `rank` highest numbers of the ranges, or the highest `rank` percent of them.

**Exceptions**

- `ArgumentOutOfRangeException`: The rank is outside 1 to 1000, or a percentage outside 1 to 100.

<a id="uniquevalues-conditionalstyle"></a>
### UniqueValues(ConditionalStyle)

```csharp
public static ConditionalFormat UniqueValues(ConditionalStyle style)
```

Values that appear once in the ranges.
