Added new conditional formatting

This commit is contained in:
dfinke
2016-01-19 17:31:16 -05:00
parent d0d79d8bf7
commit fc3a17bec8
2 changed files with 23 additions and 6 deletions

View File

@@ -341,10 +341,16 @@ function Export-Excel {
foreach ($targetConditionalText in $ConditionalText) { foreach ($targetConditionalText in $ConditionalText) {
$target = "Add$($targetConditionalText.ConditionalType)" $target = "Add$($targetConditionalText.ConditionalType)"
$rule=($ws.Cells[$ws.Dimension.Address].ConditionalFormatting).$target() $Range=$targetConditionalText.Range
$rule.Text = $targetConditionalText.Text if(!$Range) { $Range=$ws.Dimension.Address }
$rule.Style.Font.Color.Color = $targetConditionalText.ConditionalTextColor
$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.PatternType=$targetConditionalText.PatternType
$rule.Style.Fill.BackgroundColor.Color=$targetConditionalText.BackgroundColor $rule.Style.Fill.BackgroundColor.Color=$targetConditionalText.BackgroundColor
} }

View File

@@ -1,12 +1,22 @@
function New-ConditionalText { function New-ConditionalText {
param( param(
[Parameter(Mandatory=$true)] #[Parameter(Mandatory=$true)]
$Text, $Text,
[System.Drawing.Color]$ConditionalTextColor="DarkRed", [System.Drawing.Color]$ConditionalTextColor="DarkRed",
[System.Drawing.Color]$BackgroundColor="LightPink", [System.Drawing.Color]$BackgroundColor="LightPink",
[String]$Range,
[OfficeOpenXml.Style.ExcelFillStyle]$PatternType=[OfficeOpenXml.Style.ExcelFillStyle]::Solid, [OfficeOpenXml.Style.ExcelFillStyle]$PatternType=[OfficeOpenXml.Style.ExcelFillStyle]::Solid,
[ValidateSet("ContainsText","NotContainsText","BeginsWith","EndsWith")] [ValidateSet(
$ConditionalType="ContainsText" "ContainsText","NotContainsText","BeginsWith","EndsWith",
"Last7Days","LastMonth","LastWeek",
"NextMonth","NextWeek",
"ThisMonth","ThisWeek",
"Today","Tomorrow","Yesterday",
"DuplicateValues",
"AboveOrEqualAverage","BelowAverage","AboveAverage",
"Top", "TopPercent"
)]
$ConditionalType="ContainsText"
) )
$obj = [PSCustomObject]@{ $obj = [PSCustomObject]@{
@@ -14,6 +24,7 @@ function New-ConditionalText {
ConditionalTextColor = $ConditionalTextColor ConditionalTextColor = $ConditionalTextColor
ConditionalType = $ConditionalType ConditionalType = $ConditionalType
PatternType = $PatternType PatternType = $PatternType
Range = $Range
BackgroundColor = $BackgroundColor BackgroundColor = $BackgroundColor
} }