Public/PSWordLists.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function Add-WordList {
    [CmdletBinding()]
    param (
        [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument,
        [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph,
        [ListItemType]$ListType,
        [string[]] $ListData = $null,
        $Object = $null,
        $Supress = $true
    )
    $LevelPrimary = 0
    $LevelSecondary = 1
    $LevelThird = 2
    if ($ListData -ne $null) {
        $ListCount = ($ListData | Measure-Object).Count
        If ($ListCount -gt 0) {
            $List = $WordDocument.AddList($ListData[0], 0, $ListType)
            Write-Verbose "AddList - Name: $($List.GetType().Name) - BaseType: $($List.GetType().BaseType)"
            for ($i = 1; $i -lt $ListData.Count; $i++ ) {
                $ListItem = $WordDocument.AddListItem($List, $ListData[$i])
                Write-Verbose "AddList - Name: $($ListItem.GetType().Name) - BaseType: $($ListItem.GetType().BaseType)"
            }
            if ($Paragraph -ne $null) {
                $data = $Paragraph.InsertList($List)
            } else {
                $data = $WordDocument.InsertList($List)
            }
        }
    }
    if ($Object -ne $null) {

        $IsFirstTitle = $True
        $Titles = Get-ObjectTitles -Object $Object
        foreach ($Title in $Titles) {
            $Values = Get-ObjectData -Object $Object -Title $Title
            #$Values
            $IsFirstValue = $True
            foreach ($Value in $Values) {
                if ($IsFirstTitle -eq $True) {
                    $List = $WordDocument.AddList($Value, $LevelPrimary, $ListType)
                    Write-Verbose "AddList (Object) - Name: $($List.GetType().Name) - BaseType: $($List.GetType().BaseType)"
                } else {
                    #Write-Color 'Value IsFirstTitle ', $IsFirstTitle, ' Value IsFirstValue ', $IsFirstValue, ' Count ', $Values.Count, ' Value: ', $Value -Color Yellow, Green, Yellow, Green, White, Yellow
                    if ($IsFirstValue -eq $True) {
                        $ListItem = $WordDocument.AddListItem($List, $Value, $LevelPrimary) #> $null
                        Write-Verbose "AddList (Object) - Name: $($ListItem.GetType().Name) - BaseType: $($ListItem.GetType().BaseType)"
                    } else {
                        $ListItem = $WordDocument.AddListItem($List, $Value, $LevelSecondary) # > $null
                        Write-Verbose "AddList (Object) - Name: $($ListItem.GetType().Name) - BaseType: $($ListItem.GetType().BaseType)"
                    }
                }
                $IsFirstTitle = $false
                $IsFirstValue = $false
            }
        }
        if ($Paragraph -ne $null) {
            $data = $Paragraph.InsertList($List)
        } else {
            $data = $WordDocument.InsertList($List) #| Out-Null
        }
    }
    Write-Verbose "AddList - Name: $($data.GetType().Name) - BaseType: $($data.GetType().BaseType)"
    if ($supress -eq $false) {
        return $data
    } else {
        return
    }
}

function Convert-ListToHeadings {
    [CmdletBinding()]
    param(
        [Xceed.Words.NET.Container] $WordDocument,
        $List,
        [alias ("HT")] [HeadingType] $HeadingType = [HeadingType]::Heading1
    )
    $Headings = New-ArrayList
    $List.GetType()
    $Paragraphs = Get-WordParagraphForList $WordDocument $List.NumID
    foreach ($p in $Paragraphs) {
        $p.StyleName = $HeadingType
        Add-ToArray -List $Headings -Element $p
    }
    return $Headings
}