mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-06 00:23:20 +00:00
Added new conditional formatting
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
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")]
|
||||
[ValidateSet(
|
||||
"ContainsText","NotContainsText","BeginsWith","EndsWith",
|
||||
"Last7Days","LastMonth","LastWeek",
|
||||
"NextMonth","NextWeek",
|
||||
"ThisMonth","ThisWeek",
|
||||
"Today","Tomorrow","Yesterday",
|
||||
"DuplicateValues",
|
||||
"AboveOrEqualAverage","BelowAverage","AboveAverage",
|
||||
"Top", "TopPercent"
|
||||
)]
|
||||
$ConditionalType="ContainsText"
|
||||
)
|
||||
|
||||
@@ -14,6 +24,7 @@ function New-ConditionalText {
|
||||
ConditionalTextColor = $ConditionalTextColor
|
||||
ConditionalType = $ConditionalType
|
||||
PatternType = $PatternType
|
||||
Range = $Range
|
||||
BackgroundColor = $BackgroundColor
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user