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
24
25
26
27
28
29
30
31
32
33
34
35
function New-ConditionalText {
    param(
        #[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(
               "LessThan","LessThanOrEqual","GreaterThan","GreaterThanOrEqual",
            "NotEqual","Equal","ContainsText","NotContainsText","BeginsWith","EndsWith",
            "Last7Days","LastMonth","LastWeek",
            "NextMonth","NextWeek",
            "ThisMonth","ThisWeek",
            "Today","Tomorrow","Yesterday",
            "DuplicateValues",
            "AboveOrEqualAverage","BelowAverage","AboveAverage",
            "Top", "TopPercent", "ContainsBlanks"
        )]
        $ConditionalType="ContainsText"
    )

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

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