Project

PSWriteOffice

PowerShell document automation across Word, Excel, PowerPoint, PDF, Reader, Confluence, Visio, and open text formats.

Stars 159
Forks 14
PowerShell Gallery downloads 158,661
Release v3.0.5
Language: C# Updated: 2026-09-03

API Reference

Cmdlet

Add-OfficeExcelConditionalRule

Aliases: ExcelConditionalRule
Namespace PSWriteOffice
Aliases
ExcelConditionalRule
Inputs
OfficeIMO.Excel.ExcelDocument

Adds a conditional formatting rule to the current worksheet.

Remarks

Adds a conditional formatting rule to the current worksheet.

Examples

Authored help example

Highlight values greater than 100.

PS>


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

Applies a conditional rule to column C.

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.

Syntax

Add-OfficeExcelConditionalRule [-EqualAverage] [-Formula1 <String>] [-Formula2 <String>] [-HeaderName <String>] [-HeaderRow <Int32>] [-IncludeHeader] [-Operator <LessThan>] [-PassThru] [-Percent] [-PivotTableName <String>] [-PivotWholeTable] [-Range <String>] [-Rank <UInt32>] [-RuleType <CellIs>] [-StandardDeviation <UInt32>] [-StopIfTrue] [-TableName <String>] [-Text <String>] [-TimePeriod <Today>] [<CommonParameters>]
#
Parameter set: Context

Parameters

EqualAverage SwitchParameter optionalposition: namedpipeline: False
Include values equal to the average for average rules.
Formula1 String optionalposition: 2pipeline: False
Primary formula or value.
Formula2 String optionalposition: namedpipeline: False
Optional secondary formula or value.
HeaderName String optionalposition: namedpipeline: Falsealiases: ColumnName
Header or table column name used to resolve the target range.
HeaderRow Int32 optionalposition: namedpipeline: False
Worksheet header row used when resolving HeaderName without a table. Use 0 for the first row of the used range.
IncludeHeader SwitchParameter optionalposition: namedpipeline: False
Include the header cell in the resolved range.
Operator ExcelConditionalFormattingOperator optionalposition: 1pipeline: Falsevalues: 12
Conditional formatting operator.
Possible values: LessThan, LessThanOrEqual, Equal, NotEqual, GreaterThanOrEqual, GreaterThan, Between, NotBetween, ContainsText, NotContains, BeginsWith, EndsWith
PassThru SwitchParameter optionalposition: namedpipeline: False
Emit the range after applying the rule.
Percent SwitchParameter optionalposition: namedpipeline: False
Treat top/bottom rank as a percent.
PivotTableName String optionalposition: namedpipeline: False
Pivot table name used to resolve the target range.
PivotWholeTable SwitchParameter optionalposition: namedpipeline: False
Use the full pivot output range instead of the default data body range.
Range String optionalposition: 0pipeline: False
A1 range to apply the rule to.
Rank UInt32 optionalposition: namedpipeline: False
Rank used by top/bottom rules.
RuleType OfficeExcelConditionalRuleType optionalposition: namedpipeline: Falsealiases: Typevalues: 20
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 optionalposition: namedpipeline: False
Optional standard deviation threshold for average rules.
StopIfTrue SwitchParameter optionalposition: namedpipeline: False
Stop evaluating later rules when this rule is true.
TableName String optionalposition: namedpipeline: False
Optional table name for header-based range resolution.
Text String optionalposition: namedpipeline: False
Text used by text-matching rule types.
TimePeriod ExcelConditionalTimePeriod optionalposition: namedpipeline: Falsevalues: 10
Time period used by time-period rules.
Possible values: Today, Yesterday, Tomorrow, Last7Days, ThisMonth, LastMonth, NextMonth, ThisWeek, LastWeek, NextWeek
Add-OfficeExcelConditionalRule -Document <ExcelDocument> [-EqualAverage] [-Formula1 <String>] [-Formula2 <String>] [-HeaderName <String>] [-HeaderRow <Int32>] [-IncludeHeader] [-Operator <LessThan>] [-PassThru] [-Percent] [-PivotTableName <String>] [-PivotWholeTable] [-Range <String>] [-Rank <UInt32>] [-RuleType <CellIs>] [-Sheet <String>] [-SheetIndex <Int32>] [-StandardDeviation <UInt32>] [-StopIfTrue] [-TableName <String>] [-Text <String>] [-TimePeriod <Today>] [<CommonParameters>]
#
Parameter set: Document

Parameters

Document ExcelDocument requiredposition: namedpipeline: True (ByValue)
Workbook to operate on outside the DSL context.
EqualAverage SwitchParameter optionalposition: namedpipeline: False
Include values equal to the average for average rules.
Formula1 String optionalposition: 2pipeline: False
Primary formula or value.
Formula2 String optionalposition: namedpipeline: False
Optional secondary formula or value.
HeaderName String optionalposition: namedpipeline: Falsealiases: ColumnName
Header or table column name used to resolve the target range.
HeaderRow Int32 optionalposition: namedpipeline: False
Worksheet header row used when resolving HeaderName without a table. Use 0 for the first row of the used range.
IncludeHeader SwitchParameter optionalposition: namedpipeline: False
Include the header cell in the resolved range.
Operator ExcelConditionalFormattingOperator optionalposition: 1pipeline: Falsevalues: 12
Conditional formatting operator.
Possible values: LessThan, LessThanOrEqual, Equal, NotEqual, GreaterThanOrEqual, GreaterThan, Between, NotBetween, ContainsText, NotContains, BeginsWith, EndsWith
PassThru SwitchParameter optionalposition: namedpipeline: False
Emit the range after applying the rule.
Percent SwitchParameter optionalposition: namedpipeline: False
Treat top/bottom rank as a percent.
PivotTableName String optionalposition: namedpipeline: False
Pivot table name used to resolve the target range.
PivotWholeTable SwitchParameter optionalposition: namedpipeline: False
Use the full pivot output range instead of the default data body range.
Range String optionalposition: 0pipeline: False
A1 range to apply the rule to.
Rank UInt32 optionalposition: namedpipeline: False
Rank used by top/bottom rules.
RuleType OfficeExcelConditionalRuleType optionalposition: namedpipeline: Falsealiases: Typevalues: 20
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
Sheet String optionalposition: namedpipeline: False
Worksheet name when using Document.
SheetIndex Int32 optionalposition: namedpipeline: False
Worksheet index (0-based) when using Document.
StandardDeviation UInt32 optionalposition: namedpipeline: False
Optional standard deviation threshold for average rules.
StopIfTrue SwitchParameter optionalposition: namedpipeline: False
Stop evaluating later rules when this rule is true.
TableName String optionalposition: namedpipeline: False
Optional table name for header-based range resolution.
Text String optionalposition: namedpipeline: False
Text used by text-matching rule types.
TimePeriod ExcelConditionalTimePeriod optionalposition: namedpipeline: Falsevalues: 10
Time period used by time-period rules.
Possible values: Today, Yesterday, Tomorrow, Last7Days, ThisMonth, LastMonth, NextMonth, ThisWeek, LastWeek, NextWeek