New-ConditionalText.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function New-ConditionalText {
    param(
        [Parameter(Mandatory=$true)]
        $Text,
        [System.Drawing.Color]$ConditionalTextColor="DarkRed",
        [System.Drawing.Color]$BackgroundColor="LightPink",
        [OfficeOpenXml.Style.ExcelFillStyle]$PatternType=[OfficeOpenXml.Style.ExcelFillStyle]::Solid,
        [ValidateSet("ContainsText","NotContainsText","BeginsWith","EndsWith")]
        $ConditionalType="ContainsText"        
    )

    $obj = [PSCustomObject]@{
        Text                 = $Text
        ConditionalTextColor = $ConditionalTextColor
        ConditionalType      = $ConditionalType 
        PatternType          = $PatternType 
        BackgroundColor      = $BackgroundColor 
    }

    $obj.pstypenames.Clear()
    $obj.pstypenames.Add("ConditionalText")
    $obj       
}