# Add-OfficeExcelConditionalRule

Adds a conditional formatting rule to the current worksheet.

Project

PSWriteOffice

PowerShell document automation across OfficeIMO's document, spreadsheet, presentation, PDF, Project, Access, EPUB, invoicing, and conversion engines.

[View on GitHub](https://github.com/EvotecIT/OfficeIMO/tree/master/PowerShell/PSWriteOffice) [Visit Website](#) [Releases](https://github.com/EvotecIT/PSWriteOffice/releases/tag/v3.0.5) [Changelog](#) [Get package](https://www.powershellgallery.com/packages/PSWriteOffice/0.2.0)

Stars **725**

Forks **84**

Open issues **3**

Total downloads **5,231,343**

Release **OfficeIMO-v3.6.2**

Language: C# Updated: 2026-11-23

Cmdlet 

Aliases: ExcelConditionalRule

**Module**

`PSWriteOffice`

**Aliases**

`ExcelConditionalRule`

**Inputs**

`OfficeIMO.Excel.ExcelDocument`

**Source**

[AddOfficeExcelConditionalRuleCommand.cs:18](https://github.com/EvotecIT/PSWriteOffice/blob/main/Sources/PSWriteOffice/Cmdlets/Excel/AddOfficeExcelConditionalRuleCommand.cs#L18) 

Adds a conditional formatting rule to the current worksheet.

## Syntax

```
Add-OfficeExcelConditionalRule
[-EqualAverage]
[[-Formula1] <String>]
[-Formula2 <String>]
[-HeaderName <String>]
[-HeaderRow <Int32>]
[-IncludeHeader]
[[-Operator] <ExcelConditionalFormattingOperator>]
[-PassThru]
[-Percent]
[-PivotTableName <String>]
[-PivotWholeTable]
[[-Range] <String>]
[-Rank <UInt32>]
[-RuleType <OfficeExcelConditionalRuleType>]
[-StandardDeviation <UInt32>]
[-StopIfTrue]
[-TableName <String>]
[-Text <String>]
[-TimePeriod <ExcelConditionalTimePeriod>]
[<CommonParameters>]
```

[#](#member-14dc7f495e0144a0dc7fb5ea)

Parameter set: `Context`

```
Add-OfficeExcelConditionalRule
-Document <ExcelDocument>
[-EqualAverage]
[[-Formula1] <String>]
[-Formula2 <String>]
[-HeaderName <String>]
[-HeaderRow <Int32>]
[-IncludeHeader]
[[-Operator] <ExcelConditionalFormattingOperator>]
[-PassThru]
[-Percent]
[-PivotTableName <String>]
[-PivotWholeTable]
[[-Range] <String>]
[-Rank <UInt32>]
[-RuleType <OfficeExcelConditionalRuleType>]
[-Sheet <String>]
[-SheetIndex <Int32>]
[-StandardDeviation <UInt32>]
[-StopIfTrue]
[-TableName <String>]
[-Text <String>]
[-TimePeriod <ExcelConditionalTimePeriod>]
[<CommonParameters>]
```

[#](#member-6372bda8a635431b4d081892)

Parameter set: `Document`

## Examples

### Highlight values greater than 100.

```powershell
ExcelSheet 'Data' { Add-OfficeExcelConditionalRule -Range 'C2:C100' -Operator GreaterThan -Formula1 '100' }
```

Applies a conditional rule to column C.

## Parameters

**-EqualAverage SwitchParameter optional**

Include values equal to the average for average rules.

**-Formula1 String optionalposition: 2**

Primary formula or value.

**-Formula2 String optional**

Optional secondary formula or value.

**-HeaderName String optionalaliases: ColumnName**

Header or table column name used to resolve the target range.

**-HeaderRow Int32 optional**

Worksheet header row used when resolving HeaderName without a table. Use 0 for the first row of the used range.

**-IncludeHeader SwitchParameter optional**

Include the header cell in the resolved range.

**-Operator ExcelConditionalFormattingOperator optionalposition: 1**

Conditional formatting operator.

Possible values: `LessThan`, `LessThanOrEqual`, `Equal`, `NotEqual`, `GreaterThanOrEqual`, `GreaterThan`, `Between`, `NotBetween`, `ContainsText`, `NotContains`, `BeginsWith`, `EndsWith`

**-PassThru SwitchParameter optional**

Emit the range after applying the rule.

**-Percent SwitchParameter optional**

Treat top/bottom rank as a percent.

**-PivotTableName String optional**

Pivot table name used to resolve the target range.

**-PivotWholeTable SwitchParameter optional**

Use the full pivot output range instead of the default data body range.

**-Range String optionalposition: 0**

A1 range to apply the rule to.

**-Rank UInt32 optional**

Rank used by top/bottom rules.

**-RuleType OfficeExcelConditionalRuleType optionalaliases: Type**

Rule type to author.

Possible values: `CellIs`, `Expression`, `Formula`, `DuplicateValues`, `UniqueValues`, `Top`, `Top10`, `Bottom`, `Bottom10`, `AboveAverage`, `BelowAverage`, `ContainsText`, `NotContainsText`, `BeginsWith`, `EndsWith`, `ContainsBlanks`, `NotContainsBlanks`, `ContainsErrors`, `NotContainsErrors`, `TimePeriod`

**-StandardDeviation UInt32 optional**

Optional standard deviation threshold for average rules.

**-StopIfTrue SwitchParameter optional**

Stop evaluating later rules when this rule is true.

**-TableName String optional**

Optional table name for header-based range resolution.

**-Text String optional**

Text used by text-matching rule types.

**-TimePeriod ExcelConditionalTimePeriod optional**

Time period used by time-period rules.

Possible values: `Today`, `Yesterday`, `Tomorrow`, `Last7Days`, `ThisMonth`, `LastMonth`, `NextMonth`, `ThisWeek`, `LastWeek`, `NextWeek`

**-Document ExcelDocument requiredpipeline: True (ByValue)sets: Document**

Workbook to operate on outside the DSL context.

**-Sheet String optionalsets: Document**

Worksheet name when using Document.

**-SheetIndex Int32 optionalsets: Document**

Worksheet index (0-based) when using Document.

## Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see [about_CommonParameters](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_commonparameters).

Evotec API Reference Copyright 2026 Evotec Services

<!-- PowerForge markdown artifact sha256:C636416172BEBFA5494D7DF0C57183D92919D42F7D20E67D1C22B1EC532D14E1 -->
