diff --git a/Export-Excel.ps1 b/Export-Excel.ps1 index cd330b7..717acaa 100644 --- a/Export-Excel.ps1 +++ b/Export-Excel.ps1 @@ -341,10 +341,16 @@ function Export-Excel { foreach ($targetConditionalText in $ConditionalText) { $target = "Add$($targetConditionalText.ConditionalType)" - $rule=($ws.Cells[$ws.Dimension.Address].ConditionalFormatting).$target() - $rule.Text = $targetConditionalText.Text - $rule.Style.Font.Color.Color = $targetConditionalText.ConditionalTextColor + $Range=$targetConditionalText.Range + if(!$Range) { $Range=$ws.Dimension.Address } + + $rule=($ws.Cells[$Range].ConditionalFormatting).$target() + if($targetConditionalText.Text) { + $rule.Text = $targetConditionalText.Text + } + + $rule.Style.Font.Color.Color = $targetConditionalText.ConditionalTextColor $rule.Style.Fill.PatternType=$targetConditionalText.PatternType $rule.Style.Fill.BackgroundColor.Color=$targetConditionalText.BackgroundColor } diff --git a/New-ConditionalText.ps1 b/New-ConditionalText.ps1 index dde37b1..40629be 100644 --- a/New-ConditionalText.ps1 +++ b/New-ConditionalText.ps1 @@ -1,12 +1,22 @@ function New-ConditionalText { param( - [Parameter(Mandatory=$true)] + #[Parameter(Mandatory=$true)] $Text, [System.Drawing.Color]$ConditionalTextColor="DarkRed", [System.Drawing.Color]$BackgroundColor="LightPink", + [String]$Range, [OfficeOpenXml.Style.ExcelFillStyle]$PatternType=[OfficeOpenXml.Style.ExcelFillStyle]::Solid, - [ValidateSet("ContainsText","NotContainsText","BeginsWith","EndsWith")] - $ConditionalType="ContainsText" + [ValidateSet( + "ContainsText","NotContainsText","BeginsWith","EndsWith", + "Last7Days","LastMonth","LastWeek", + "NextMonth","NextWeek", + "ThisMonth","ThisWeek", + "Today","Tomorrow","Yesterday", + "DuplicateValues", + "AboveOrEqualAverage","BelowAverage","AboveAverage", + "Top", "TopPercent" + )] + $ConditionalType="ContainsText" ) $obj = [PSCustomObject]@{ @@ -14,6 +24,7 @@ function New-ConditionalText { ConditionalTextColor = $ConditionalTextColor ConditionalType = $ConditionalType PatternType = $PatternType + Range = $Range BackgroundColor = $BackgroundColor }