Add-OfficeExcelConditionalFormat
Adds a conditional format: a rule, color scale, data bar or icon set.
Syntax
Add-OfficeExcelConditionalFormat
[-BackgroundColor <OfficeColor>]
[-Color <OfficeColor>]
[-Document <ExcelDocument>]
[-EqualAverage]
[[-Operator] <ExcelConditionalFormattingOperator>]
[-PassThru]
[-Percent]
[-Range] <String>
[-Rank <UInt32>]
[-Rule <OfficeExcelConditionalRuleType>]
[-SecondValue <String>]
[-Sheet <OfficeSheetSelector>]
[-StandardDeviation <UInt32>]
[-StopIfTrue]
[-Text <String>]
[-TimePeriod <ExcelConditionalTimePeriod>]
[[-Value] <String>]
[<CommonParameters>]#RuleRangeAdd-OfficeExcelConditionalFormat
[-Document <ExcelDocument>]
-EndColor <OfficeColor>
[-MidColor <OfficeColor>]
[-PassThru]
[-Range] <String>
[-Sheet <OfficeSheetSelector>]
-StartColor <OfficeColor>
[<CommonParameters>]#ColorScaleRangeAdd-OfficeExcelConditionalFormat
[-Color <OfficeColor>]
-DataBar
[-Document <ExcelDocument>]
[-PassThru]
[-Range] <String>
[-Sheet <OfficeSheetSelector>]
[<CommonParameters>]#DataBarRangeAdd-OfficeExcelConditionalFormat
[-Document <ExcelDocument>]
-IconSet <ExcelIconSet>
[-NoValue]
[-NumberThreshold <Double[]>]
[-PassThru]
[-PercentThreshold <Double[]>]
[-Range] <String>
[-Reverse]
[-Sheet <OfficeSheetSelector>]
[<CommonParameters>]#IconSetRangeAdd-OfficeExcelConditionalFormat
[-BackgroundColor <OfficeColor>]
[-Color <OfficeColor>]
[-Document <ExcelDocument>]
[-EqualAverage]
-Header <String>
[-HeaderRow <Int32>]
[-IncludeHeader]
[[-Operator] <ExcelConditionalFormattingOperator>]
[-PassThru]
[-Percent]
[-Rank <UInt32>]
[-Rule <OfficeExcelConditionalRuleType>]
[-SecondValue <String>]
[-Sheet <OfficeSheetSelector>]
[-StandardDeviation <UInt32>]
[-StopIfTrue]
[-Table <String>]
[-Text <String>]
[-TimePeriod <ExcelConditionalTimePeriod>]
[[-Value] <String>]
[<CommonParameters>]#RuleHeaderAdd-OfficeExcelConditionalFormat
[-BackgroundColor <OfficeColor>]
[-Color <OfficeColor>]
[-Document <ExcelDocument>]
[-EqualAverage]
[[-Operator] <ExcelConditionalFormattingOperator>]
[-PassThru]
[-Percent]
-PivotTable <String>
[-PivotWholeTable]
[-Rank <UInt32>]
[-Rule <OfficeExcelConditionalRuleType>]
[-SecondValue <String>]
[-Sheet <OfficeSheetSelector>]
[-StandardDeviation <UInt32>]
[-StopIfTrue]
[-Text <String>]
[-TimePeriod <ExcelConditionalTimePeriod>]
[[-Value] <String>]
[<CommonParameters>]#RulePivotTableAdd-OfficeExcelConditionalFormat
[-Color <OfficeColor>]
-DataBar
[-Document <ExcelDocument>]
-Header <String>
[-HeaderRow <Int32>]
[-IncludeHeader]
[-PassThru]
[-Sheet <OfficeSheetSelector>]
[-Table <String>]
[<CommonParameters>]#DataBarHeaderAdd-OfficeExcelConditionalFormat
[-Color <OfficeColor>]
-DataBar
[-Document <ExcelDocument>]
[-PassThru]
-PivotTable <String>
[-PivotWholeTable]
[-Sheet <OfficeSheetSelector>]
[<CommonParameters>]#DataBarPivotTableAdd-OfficeExcelConditionalFormat
[-Document <ExcelDocument>]
-EndColor <OfficeColor>
-Header <String>
[-HeaderRow <Int32>]
[-IncludeHeader]
[-MidColor <OfficeColor>]
[-PassThru]
[-Sheet <OfficeSheetSelector>]
-StartColor <OfficeColor>
[-Table <String>]
[<CommonParameters>]#ColorScaleHeaderAdd-OfficeExcelConditionalFormat
[-Document <ExcelDocument>]
-Header <String>
[-HeaderRow <Int32>]
-IconSet <ExcelIconSet>
[-IncludeHeader]
[-NoValue]
[-NumberThreshold <Double[]>]
[-PassThru]
[-PercentThreshold <Double[]>]
[-Reverse]
[-Sheet <OfficeSheetSelector>]
[-Table <String>]
[<CommonParameters>]#IconSetHeaderAdd-OfficeExcelConditionalFormat
[-Document <ExcelDocument>]
-EndColor <OfficeColor>
[-MidColor <OfficeColor>]
[-PassThru]
-PivotTable <String>
[-PivotWholeTable]
[-Sheet <OfficeSheetSelector>]
-StartColor <OfficeColor>
[<CommonParameters>]#ColorScalePivotTableAdd-OfficeExcelConditionalFormat
[-Document <ExcelDocument>]
-IconSet <ExcelIconSet>
[-NoValue]
[-NumberThreshold <Double[]>]
[-PassThru]
[-PercentThreshold <Double[]>]
-PivotTable <String>
[-PivotWholeTable]
[-Reverse]
[-Sheet <OfficeSheetSelector>]
[<CommonParameters>]#IconSetPivotTableExamples
Add data bars to a column
Open-OfficeExcel -Path .\Reports\Q3-Sales.xlsx {
ExcelSheet 'Orders' {
ExcelConditionalFormat -Header Amount -Table Orders -DataBar
}
}Draws data bars in the Amount column of the Orders table in the first accent colour.
Colour attainment from red to green
Open-OfficeExcel -Path .\Reports\Q3-Performance.xlsx {
ExcelSheet 'Performance' {
ExcelConditionalFormat -Header Attainment -Table Actuals -StartColor Danger -MidColor Warning -EndColor Success
ExcelConditionalFormat -Header Change -Table Actuals -IconSet ThreeArrows
}
}Applies a three-colour scale from the theme's danger to success colours to target attainment, and arrows to the change against last quarter.
Flag negative margins with a rule
Open-OfficeExcel -Path .\Reports\Q3-Sales.xlsx {
ExcelSheet 'Orders' {
ExcelConditionalFormat E2:E500 -Rule CellIs -Operator LessThan -Value 0 -BackgroundColor '#FEE2E2' -Color Danger
}
}Highlights negative margins with a light red fill and red text.
Highlight accounts with no logon in 90 days
Open-OfficeExcel -Path .\Reports\Users.xlsx {
ExcelSheet 'Users' {
ExcelConditionalFormat -Header LastLogon -Table Users -Rule CellIs -Operator LessThan -Value '=TODAY()-90' -BackgroundColor Danger
}
}Colours the LastLogon cell when the date is more than 90 days old; -Value takes an Excel formula when it starts with '='.
Parameters
- -BackgroundColor OfficeColor
- Cell fill colour expressed as a literal OfficeColor or theme role.
- -Color OfficeColor
- Text or rule colour expressed as a literal OfficeColor or theme role.
- -Document ExcelDocument
- Caller-owned workbook; omission uses the enclosing Excel content block.
- -EqualAverage SwitchParameter
- Include values equal to the average for average rules.
- -Operator ExcelConditionalFormattingOperator
- Conditional formatting operator.
- Possible values:
LessThan,LessThanOrEqual,Equal,NotEqual,GreaterThanOrEqual,GreaterThan,Between,NotBetween,ContainsText,NotContains,BeginsWith,EndsWith - -PassThru SwitchParameter
- Emits the native result after the operation.
- -Percent SwitchParameter
- Treat top/bottom rank as a percent.
- -Range String
- A1 cell range on the selected worksheet.
- -Rank UInt32
- Rank used by top/bottom rules.
- -Rule OfficeExcelConditionalRuleType
- Native conditional-format rule family; the default compares cell values.
- Possible values:
CellIs,Expression,Formula,DuplicateValues,UniqueValues,Top,Top10,Bottom,Bottom10,AboveAverage,BelowAverage,ContainsText,NotContainsText,BeginsWith,EndsWith,ContainsBlanks,NotContainsBlanks,ContainsErrors,NotContainsErrors,TimePeriod - -SecondValue String
- Upper bound or second formula used by between comparisons.
- -Sheet OfficeSheetSelector
- Worksheet name, one-based position or native worksheet object. Multi-sheet commands also accept wildcard names.
- -StandardDeviation UInt32
- Optional standard deviation threshold for average rules.
- -StopIfTrue SwitchParameter
- Stop evaluating later rules when this rule is true.
- -Text String
- Text used by text-matching rule types.
- -TimePeriod ExcelConditionalTimePeriod
- Time period used by time-period rules.
- Possible values:
Today,Yesterday,Tomorrow,Last7Days,ThisMonth,LastMonth,NextMonth,ThisWeek,LastWeek,NextWeek - -Value String
- Value or values consumed by the selected operation.
- -EndColor OfficeColor
- End color. Named colors and hexadecimal values are accepted.
- -MidColor OfficeColor
- Middle colour of a three-colour scale at the 50th percentile. Omission uses a two-colour scale.
- -StartColor OfficeColor
- Start color. Named colors and hexadecimal values are accepted.
- -DataBar SwitchParameter
- Selects the native data-bar conditional-format family.
- -IconSet ExcelIconSet
- Icon set to apply.
- Possible values:
ThreeArrows,ThreeArrowsGray,ThreeFlags,ThreeTrafficLights1,ThreeTrafficLights2,ThreeSigns,ThreeSymbols,ThreeSymbols2,FourArrows,FourArrowsGray,FourRedToBlack,FourRating,FourTrafficLights,FiveArrows,FiveArrowsGray,FiveRating,FiveQuarters - -NoValue SwitchParameter
- Hides cell values behind conditional-format icons.
- -NumberThreshold Double[]
- Numeric thresholds for native conditional-format icons.
- -PercentThreshold Double[]
- Percentage thresholds for native conditional-format icons.
- -Reverse SwitchParameter
- Reverse the icon order.
- -Header String
- Header text identifying the target column.
- -HeaderRow Int32
- One-based row containing the column headers.
- -IncludeHeader SwitchParameter
- Includes the header cell in the resolved column range.
- -Table String
- Native Excel table used to resolve the source range or header.
- -PivotTable String
- Native pivot table whose data or entire range is targeted.
- -PivotWholeTable SwitchParameter
- Use the full pivot output range instead of the default data body range.
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.