PSWriteWord.psm1
function Add-WordBarChart { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [string] $ChartName, [string[]] $Names, [int[]] $Values, [Xceed.Words.NET.Series[]] $ChartSeries, [ChartLegendPosition] $ChartLegendPosition = [ChartLegendPosition]::Left, [bool] $ChartLegendOverlay = $false, [BarGrouping] $BarGrouping = [BarGrouping]::Standard, [BarDirection] $BarDirection = [BarDirection]::Bar, [int] $BarGapWidth = 200, [switch] $NoLegend) if ($ChartSeries -eq $null) {$ChartSeries = Add-WordChartSeries -ChartName $ChartName -Names $Names -Values $Values} [Xceed.Words.NET.BarChart] $chart = New-Object -TypeName Xceed.Words.NET.BarChart $chart.BarDirection = $BarDirection $chart.BarGrouping = $BarGrouping $chart.GapWidth = $BarGapWidth if (-not $NoLegend) {$chart.AddLegend($ChartLegendPosition, $ChartLegendOverlay)} foreach ($series in $ChartSeries) {$chart.AddSeries($Series)} if ($Paragraph -eq $null) {$WordDocument.InsertChart($chart)} else {$WordDocument.InsertChartAfterParagraph($chart, $paragraph)} } function Add-WordChartSeries { param ([string] $ChartName = 'Legend', [string[]] $Names, [int[]] $Values) [Array] $rNames = foreach ($Name in $Names) {$Name} [Array] $rValues = foreach ($value in $Values) {$value} [Xceed.Words.NET.Series] $series = New-Object -TypeName Xceed.Words.NET.Series -ArgumentList $ChartName $Series.Bind($rNames, $rValues) return $Series } function Add-WordCustomProperty { [CmdletBinding()] param ([Xceed.Words.NET.Container]$WordDocument, [string] $Name, [string] $Value, [bool] $Supress) $CustomProperty = New-Object -TypeName Xceed.Words.NET.CustomProperty -ArgumentList $Name, $Value $Data = $WordDocument.AddCustomProperty($CustomProperty) if ($Supress) {return} else {return $Data} } function Add-WordEquation { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [string] $Equation, [bool] $Supress = $false) $Output = $WordDocument.InsertEquation($Equation) if ($Supress -eq $false) {return $Output} else {return} } function Add-WordFooter { [CmdletBinding()] param ([Xceed.Words.NET.Container]$WordDocument, [nullable[bool]] $DifferentFirstPage, [nullable[bool]] $DifferentOddAndEvenPages, [bool] $Supress = $false) $WordDocument.AddFooters() if ($DifferentOddAndEvenPages -ne $null) {$WordDocument.DifferentFirstPage = $DifferentFirstPage} if ($DifferentOddAndEvenPages -ne $null) {$WordDocument.DifferentOddAndEvenPages = $DifferentOddAndEvenPages} if ($Supress) {return} else {return $WordDocument.Footers} } function Add-WordHeader { [CmdletBinding()] param ([Xceed.Words.NET.Container]$WordDocument, [nullable[bool]] $DifferentFirstPage, [nullable[bool]] $DifferentOddAndEvenPages, [bool] $Supress = $false) $WordDocument.AddHeaders() if ($DifferentOddAndEvenPages -ne $null) {$WordDocument.DifferentFirstPage = $DifferentFirstPage} if ($DifferentOddAndEvenPages -ne $null) {$WordDocument.DifferentOddAndEvenPages = $DifferentOddAndEvenPages} if ($Supress) {return} else {return $WordDocument.Headers} } function Add-WordHeader { [CmdletBinding()] param ([Xceed.Words.NET.Container]$WordDocument, [nullable[bool]] $DifferentFirstPage, [nullable[bool]] $DifferentOddAndEvenPages, [bool] $Supress = $false) $WordDocument.AddHeaders() if ($DifferentOddAndEvenPages -ne $null) {$WordDocument.DifferentFirstPage = $DifferentFirstPage} if ($DifferentOddAndEvenPages -ne $null) {$WordDocument.DifferentOddAndEvenPages = $DifferentOddAndEvenPages} if ($Supress) {return} else {return $WordDocument.Headers} } function Add-WordHyperLink { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [string] $UrlText, [string] $UrlLink, [bool] $Supress = $false) $Url = New-Object -TypeName Uri -ArgumentList $UrlLink return $WordDocument.AddHyperlink($UrlText, $Url) } function Add-WordLine { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [HorizontalBorderPosition] $HorizontalBorderPosition = [HorizontalBorderPosition]::Bottom, [ValidateSet('single', 'double', 'triple')] $LineType = 'single', [nullable[int]] $LineSize = 6, [nullable[int]] $LineSpace = 1, [string] $LineColor = 'black', [bool] $Supress) if ($Paragraph -eq $null) {$Paragraph = Add-WordParagraph -WordDocument $WordDocument -Supress $False} $Paragraph = $Paragraph.InsertHorizontalLine($HorizontalBorderPosition, $LineType, $LineSize, $LineSpace, $LineColor) if ($Supress) {return} else {$Paragraph} } function Add-WordLineChart { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [string] $ChartName, [string[]] $Names, [int[]] $Values, [Xceed.Words.NET.Series[]] $ChartSeries, [ChartLegendPosition] $ChartLegendPosition = [ChartLegendPosition]::Left, [bool] $ChartLegendOverlay = $false, [switch] $NoLegend) if ($ChartSeries -eq $null) {$ChartSeries = Add-WordChartSeries -ChartName $ChartName -Names $Names -Values $Values} [Xceed.Words.NET.LineChart] $chart = New-Object -TypeName Xceed.Words.NET.LineChart if (-not $NoLegend) {$chart.AddLegend($ChartLegendPosition, $ChartLegendOverlay)} foreach ($series in $ChartSeries) {$chart.AddSeries($Series)} if ($Paragraph -eq $null) {$WordDocument.InsertChart($chart)} else {$WordDocument.InsertChartAfterParagraph($chart, $paragraph)} } function Add-WordList { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [ListItemType]$ListType = [ListItemType]::Bulleted, [alias('DataTable')][object] $ListData = $null, [InsertWhere] $InsertWhere = [InsertWhere]::AfterSelf, $BehaviourOption = 0, $ListLevels = @(), [bool] $Supress = $false) $List = $null if ($ListData -eq $null) {return} $Type = Get-ObjectType $ListData if ($Type.ObjectTypeName -match 'bool|byte|char|datetime|decimal|double|ExcelHyperLink|float|int|long|sbyte|short|string|timespan|uint|ulong|URI|ushort') {$ObjectType = $Type.ObjectTypeName} elseif ($Type.ObjectTypeInsiderName -ne '') {$ObjectType = $Type.ObjectTypeInsiderName} else {$ObjectType = $Type.ObjectTypeName} if ($ObjectType -notmatch 'bool|byte|char|datetime|decimal|double|ExcelHyperLink|float|int|long|sbyte|short|string|timespan|uint|ulong|URI|ushort' -and $ObjectType -ne 'PSCustomObject' -and $ObjectType -ne 'Hashtable' -and $ObjectType -ne 'OrderedDictionary') { $ListData = Convert-ObjectToProcess -DataTable $ListData $Type = Get-ObjectType $ListData if ($Type.ObjectTypeInsiderName -ne '') {$ObjectType = $Type.ObjectTypeInsiderName} else {$ObjectType = $Type.ObjectTypeName} Write-Verbose "Add-WordList - Outside Object BaseName: $($ListData.GetType().BaseType) Name: $($ListData.GetType().Name)" Write-Verbose "Add-WordList - Insider Object Name: $ObjectType" } if ($ObjectType -match 'bool|byte|char|datetime|decimal|double|ExcelHyperLink|float|int|long|sbyte|short|string|timespan|uint|ulong|URI|ushort') { Write-Verbose 'Add-WordList - Option 1 - Detected singular type inside array' $Counter = 0 foreach ($Value in $ListData) { if ($ListLevels -eq $null) { $List = New-WordListItem -WordDocument $WordDocument -List $List -ListType $ListType -ListValue $Value -ListLevel 0 Write-Verbose "AddList - ListItemType Name: $($List.GetType().Name) - BaseType: $($List.GetType().BaseType)" } else { $List = New-WordListItem -WordDocument $WordDocument -List $List -ListType $ListType -ListValue $Value -ListLevel $ListLevels[$Counter] $Counter++ } } } elseif ($ObjectType -eq 'Hashtable' -or $ObjectType -eq 'OrderedDictionary') { Write-Verbose "Add-WordList - Option 2 - Detected $ObjectType" foreach ($Object in $ListData) { foreach ($O in $Object.GetEnumerator()) { $TextMain = $($O.Name) $TextSub = $($O.Value) $List = Format-WordListItem -WordDocument $WordDocument -List $List -ListType $ListType -TextMain $TextMain -TextSub $TextSub -BehaviourOption $BehaviourOption } } } elseif ($ObjectType -eq 'PSCustomObject') { Write-Verbose "Add-WordList - Option 3 - Detected $ObjectType" foreach ($Object in $ListData) { $Titles = Get-ObjectTitles -Object $Object foreach ($Text in $Titles) { $TextMain = $Text $TextSub = $($Object.$Text) $List = Format-WordListItem -WordDocument $WordDocument -List $List -ListType $ListType -TextMain $TextMain -TextSub $TextSub -BehaviourOption $BehaviourOption } } } else {throw "$ObjectType is not supported - report for support with explanation what you need it to look like"} $Data = Add-WordListItem -WordDocument $WordDocument -List $List -Paragraph $Paragraph -Supress $Supress if ($supress -eq $false) {return $data} else {return} } function Add-WordListItem { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $List, [Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [InsertWhere] $InsertWhere = [InsertWhere]::AfterSelf, [bool] $Supress) if ($Paragraph -ne $null) {if ($InsertWhere -eq [InsertWhere]::AfterSelf) {$data = $Paragraph.InsertListAfterSelf($List)} elseif ($InsertWhere -eq [InsertWhere]::AfterSelf) {$data = $Paragraph.InsertListBeforeSelf($List)}} else {$data = $WordDocument.InsertList($List)} Write-Verbose "Add-WordListItem - Return Type Name: $($Data.GetType().Name) - BaseType: $($Data.GetType().BaseType)" if ($Supress) {return} else {$data} } function Add-WordPageBreak { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][alias('Paragraph', 'Table', 'List')][Xceed.Words.NET.InsertBeforeOrAfter] $WordObject, [alias('Insert')][InsertWhere] $InsertWhere = [InsertWhere]::AfterSelf, [bool] $Supress = $false) $RemovalRequired = $false if ($WordObject -eq $null) { Write-Verbose "Add-WordPageBreak - Adding temporary paragraph" $RemovalRequired = $True $WordObject = $WordDocument.InsertParagraph() } if ($InsertWhere -eq [InsertWhere]::AfterSelf) {$WordObject.InsertPageBreakAfterSelf()} else {$WordObject.InsertPageBreakBeforeSelf()} if ($RemovalRequired) { Write-Verbose "Add-WordPageBreak - Removing paragraph that was added temporary" Remove-WordParagraph -Paragraph $WordObject } if ($Supress -eq $true) {return} else {return $WordObject} } function Add-WordPageCount { [alias('Add-WordPageNumber')] param([PageNumberFormat] $PageNumberFormat = [PageNumberFormat]::normal, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Footers] $Footer, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Headers] $Header, [Alignment] $Alignment, [ValidateSet('All', 'First', 'Even', 'Odd')][string] $Type = 'All', [ValidateSet('Both', 'PageCountOnly', 'PageNumberOnly')][string] $Option = 'Both', [string] $TextBefore, [string] $TextMiddle, [string] $TextAfter, [bool] $Supress) $Paragraphs = New-GenericList if ($Footer -or $Header -or $Paragraph) { if ($null -eq $Paragraph) { if ($Type -eq 'All') { $Types = 'First', 'Even', 'Odd' foreach ($T in $Types) { if ($Footer) {$Paragraphs.Add($Footer.$T.InsertParagraph())} if ($Header) {$Paragraphs.Add($Header.$T.InsertParagraph())} } } else { if ($Footer) {$Paragraphs.Add($Footer.$Type.InsertParagraph())} if ($Header) {$Paragraphs.Add($Header.$Type.InsertParagraph())} } } else {$Paragraphs.Add($Paragraph)} foreach ($CurrentParagraph in $Paragraphs) { $CurrentParagraph = Add-WordText -Paragraph $CurrentParagraph -Text $TextBefore -AppendToExistingParagraph -Alignment $Alignment if ($Option -eq 'Both' -or $Option -eq 'PageNumberOnly') {$CurrentParagraph.AppendPageNumber($PageNumberFormat)} $CurrentParagraph = Add-WordText -Paragraph $CurrentParagraph -Text $TextMiddle -AppendToExistingParagraph if ($Option -eq 'Both' -or $Option -eq 'PageCountOnly') {$CurrentParagraph.AppendPageCount($PageNumberFormat)} $CurrentParagraph = Add-WordText -Paragraph $CurrentParagraph -Text $TextAfter -AppendToExistingParagraph } if ($Supress) {return} else {return $Paragraphs} } else {Write-Warning -Message 'Add-WordPageCount - Footer or Header or Paragraph is required.'} } Function Add-WordParagraph { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [alias('Paragraph', 'Table', 'List')][Xceed.Words.NET.InsertBeforeOrAfter] $WordObject, [alias('Insert')][InsertWhere] $InsertWhere = [InsertWhere]::AfterSelf, [bool] $Supress = $false) $NewParagraph = $WordDocument.InsertParagraph() if ($WordObject -ne $null) {if ($InsertWhere -eq [InsertWhere]::AfterSelf) {$NewParagraph = $WordObject.InsertParagraphAfterSelf($NewParagraph)} elseif ($InsertWhere -eq [InsertWhere]::BeforeSelf) {$NewParagraph = $WordObject.InsertParagraphBeforeSelf($NewParagraph)}} if ($Supress -eq $true) {return} else {return $NewParagraph} } function Add-WordPicture { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [Xceed.Words.NET.DocXElement] $Picture, [alias('FileImagePath')][string] $ImagePath, [Alignment] $Alignment, [int] $Rotation, [switch] $FlipHorizontal, [switch] $FlipVertical, [int] $ImageWidth, [int] $ImageHeight, [string] $Description, [bool] $Supress = $false) if ([string]::IsNullOrEmpty($Paragraph)) {$Paragraph = Add-WordParagraph -WordDocument $WordDocument -Supress $false} if ($null -eq $Picture) { if ($ImagePath -ne '' -and (Test-Path($ImagePath))) { $Image = $WordDocument.AddImage($ImagePath) $Picture = $Image.CreatePicture() } else { Write-Warning "Add-WordPicture - Path to ImagePath ($ImagePath) was incorrect. Aborting." return } } if ($Rotation -ne 0) {$Picture.Rotation = $Rotation} if ($FlipHorizontal -ne $false) {$Picture.FlipHorizontal = $FlipHorizontal} if ($FlipVertical -ne $false) {$Picture.FlipVertical = $FlipVertical} if (-not [string]::IsNullOrEmpty($Description)) {$Picture.Description = $Description} if ($ImageWidth -ne 0) {$Picture.Width = $ImageWidth} if ($ImageHeight -ne 0) {$Picture.Height = $ImageHeight} $Data = $Paragraph.AppendPicture($Picture) if ($Alignment) {$Data = Set-WordTextAlignment -Paragraph $Data -Alignment $Alignment} if ($Supress) {return $Data} else {return} } function Add-WordPieChart { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [string] $ChartName, [string[]] $Names, [int[]] $Values, [ChartLegendPosition] $ChartLegendPosition = [ChartLegendPosition]::Left, [bool] $ChartLegendOverlay = $false, [switch] $NoLegend) $Series = Add-WordChartSeries -ChartName $ChartName -Names $Names -Values $Values [Xceed.Words.NET.PieChart] $chart = New-Object -TypeName Xceed.Words.NET.PieChart if (-not $NoLegend) {$chart.AddLegend($ChartLegendPosition, $ChartLegendOverlay)} $chart.AddSeries($Series) if ($Paragraph -eq $null) {$WordDocument.InsertChart($chart)} else {$WordDocument.InsertChartAfterParagraph($chart, $paragraph)} } function Add-WordProtection { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [EditRestrictions] $EditRestrictions, [string] $Password) if ($Password -eq $null) {$WordDocument.AddProtection($EditRestrictions)} else {$WordDocument.AddPasswordProtection($EditRestrictions, $Password)} } function Add-WordSection { [CmdletBinding()] param ([Parameter(Mandatory = $true, ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [switch] $PageBreak, [bool] $Supress) if ($PageBreak) {$Data = $WordDocument.InsertSectionPageBreak()} else {$Data = $WordDocument.InsertSection()} if ($Supress -eq $true) {return} else {return $Data} } function Add-WordTable { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Table, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Array] $DataTable, [AutoFit] $AutoFit, [TableDesign] $Design, [Direction] $Direction, [switch] $BreakPageAfterTable, [switch] $BreakPageBeforeTable, [nullable[bool]] $BreakAcrossPages, [nullable[int]] $MaximumColumns, [string[]]$Titles = @('Name', 'Value'), [switch] $DoNotAddTitle, [alias ("ColummnWidth")][float[]] $ColumnWidth = @(), [nullable[float]] $TableWidth = $null, [bool] $Percentage, [alias ("C")] [System.Drawing.Color[]]$Color = @(), [alias ("S")] [double[]] $FontSize = @(), [alias ("FontName")] [string[]] $FontFamily = @(), [alias ("B")] [nullable[bool][]] $Bold = @(), [alias ("I")] [nullable[bool][]] $Italic = @(), [alias ("U")] [UnderlineStyle[]] $UnderlineStyle = @(), [alias ('UC')] [System.Drawing.Color[]]$UnderlineColor = @(), [alias ("SA")] [double[]] $SpacingAfter = @(), [alias ("SB")] [double[]] $SpacingBefore = @(), [alias ("SP")] [double[]] $Spacing = @(), [alias ("H")] [highlight[]] $Highlight = @(), [alias ("CA")] [CapsStyle[]] $CapsStyle = @(), [alias ("ST")] [StrikeThrough[]] $StrikeThrough = @(), [alias ("HT")] [HeadingType[]] $HeadingType = @(), [int[]] $PercentageScale = @(), [Misc[]] $Misc = @(), [string[]] $Language = @(), [int[]]$Kerning = @(), [nullable[bool][]]$Hidden = @(), [int[]]$Position = @(), [single[]] $IndentationFirstLine = @(), [single[]] $IndentationHanging = @(), [Alignment[]] $Alignment = @(), [Direction[]] $DirectionFormatting = @(), [ShadingType[]] $ShadingType = @(), [Script[]] $Script = @(), [nullable[bool][]] $NewLine = @(), [switch] $KeepLinesTogether, [switch] $KeepWithNextParagraph, [switch] $ContinueFormatting, [alias('Rotate', 'RotateData', 'TransposeColumnsRows', 'TransposeData')][switch] $Transpose, [string[]] $ExcludeProperty, [switch] $NoAliasOrScriptProperties, [switch] $DisplayPropertySet, [bool] $Supress = $false, [switch] $VerboseColor) Begin { [int] $Run = 0 [int] $RowNr = 0 if ($MaximumColumns -eq $null) {$MaximumColumns = 5} } Process { if ($Run -eq 0) { if ($Transpose) {$DataTable = Format-TransposeTable -Object $DataTable} $Data = Format-PSTable -Object $DataTable -ExcludeProperty $ExcludeProperty -NoAliasOrScriptProperties:$NoAliasOrScriptProperties -DisplayPropertySet:$DisplayPropertySet $WorksheetHeaders = $Data[0] $NumberRows = $Data.Count $NumberColumns = if ($Data[0].Count -ge $MaximumColumns) {$MaximumColumns} else {$Data[0].Count} if ($null -eq $Table) {$Table = New-WordTable -WordDocument $WordDocument -Paragraph $Paragraph -NrRows $NumberRows -NrColumns $NumberColumns -Supress $false} else {Add-WordTableRow -Table $Table -Count $NumberRows -Supress $True} $Run++ } else { $Data = Format-PSTable -Object $DataTable -SkipTitle -NoAliasOrScriptProperties:$NoAliasOrScriptProperties -DisplayPropertySet:$DisplayPropertySet -OverwriteHeaders $WorksheetHeaders $NumberRows = $Data.Count $NumberColumns = if ($Data[0].Count -ge $MaximumColumns) {$MaximumColumns} else {$Data[0].Count} if ($null -eq $Table) {$Table = New-WordTable -WordDocument $WordDocument -Paragraph $Paragraph -NrRows $NumberRows -NrColumns $NumberColumns -Supress $false} else {Add-WordTableRow -Table $Table -Count $NumberRows -Supress $True} $Run++ } if ($ContinueFormatting -eq $true) { $Formatting = Set-WordContinueFormatting -Count $NumberRows -Color $Color -FontSize $FontSize -FontFamily $FontFamily -Bold $Bold -Italic $Italic -UnderlineStyle $UnderlineStyle -UnderlineColor $UnderlineColor -SpacingAfter $SpacingAfter -SpacingBefore $SpacingBefore -Spacing $Spacing -Highlight $Highlight -CapsStyle $CapsStyle -StrikeThrough $StrikeThrough -HeadingType $HeadingType -PercentageScale $PercentageScale -Misc $Misc -Language $Language -Kerning $Kerning -Hidden $Hidden -Position $Position -IndentationFirstLine $IndentationFirstLine -IndentationHanging $IndentationHanging -Alignment $Alignment -DirectionFormatting $DirectionFormatting -ShadingType $ShadingType -Script $Script $Color = $Formatting[0] $FontSize = $Formatting[1] $FontFamily = $Formatting[2] $Bold = $Formatting[3] $Italic = $Formatting[4] $UnderlineStyle = $Formatting[5] $UnderlineColor = $Formatting[6] $SpacingAfter = $Formatting[7] $SpacingBefore = $Formatting[8] $Spacing = $Formatting[9] $Highlight = $Formatting[10] $CapsStyle = $Formatting[11] $StrikeThrough = $Formatting[12] $HeadingType = $Formatting[13] $PercentageScale = $Formatting[14] $Misc = $Formatting[15] $Language = $Formatting[16] $Kerning = $Formatting[17] $Hidden = $Formatting[18] $Position = $Formatting[19] $IndentationFirstLine = $Formatting[20] $IndentationHanging = $Formatting[21] $Alignment = $Formatting[22] $DirectionFormatting = $Formatting[23] $ShadingType = $Formatting[24] $Script = $Formatting[25] } foreach ($Row in $Data) { $ColumnNr = 0 foreach ($Column in $Row) { if ($VerboseColor) {Write-Color 'Row: ', $RowNr, ' Column: ', $ColumnNr, " Data: ", $Column -Color White, Yellow, White, Green} Write-Verbose "Row: $RowNr Column: $ColumnNr Data: $Column" $Data = Add-WordTableCellValue -Table $Table -Row $RowNr -Column $ColumnNr -Value $Column -Color $Color[$RowNr] -FontSize $FontSize[$RowNr] -FontFamily $FontFamily[$RowNr] -Bold $Bold[$RowNr] -Italic $Italic[$RowNr] -UnderlineStyle $UnderlineStyle[$RowNr]-UnderlineColor $UnderlineColor[$RowNr]-SpacingAfter $SpacingAfter[$RowNr] -SpacingBefore $SpacingBefore[$RowNr] -Spacing $Spacing[$RowNr] -Highlight $Highlight[$RowNr] -CapsStyle $CapsStyle[$RowNr] -StrikeThrough $StrikeThrough[$RowNr] -HeadingType $HeadingType[$RowNr] -PercentageScale $PercentageScale[$RowNr] -Misc $Misc[$RowNr] -Language $Language[$RowNr]-Kerning $Kerning[$RowNr]-Hidden $Hidden[$RowNr]-Position $Position[$RowNr]-IndentationFirstLine $IndentationFirstLine[$RowNr]-IndentationHanging $IndentationHanging[$RowNr]-Alignment $Alignment[$RowNr]-DirectionFormatting $DirectionFormatting[$RowNr] -ShadingType $ShadingType[$RowNr]-Script $Script[$RowNr] if ($ColumnNr -eq $($MaximumColumns - 1)) {break} $ColumnNr++ } $RowNr++ } } End { $Table | Set-WordTableColumnWidth -Width $ColumnWidth -TotalWidth $TableWidth -Percentage $Percentage -Supress $True $Table | Set-WordTable -Direction $Direction -AutoFit $AutoFit -Design $Design -BreakPageAfterTable:$BreakPageAfterTable -BreakPageBeforeTable:$BreakPageBeforeTable -BreakAcrossPages $BreakAcrossPages -Supress $True if ($Supress) {return} else {return $Table} } } function Add-WordTableCellValue { [CmdletBinding()] param([Xceed.Words.NET.InsertBeforeOrAfter] $Table, [int] $Row, [int] $Column, [Object] $Value, [int] $ParagraphNumber = 0, [alias ("C")] [nullable[System.Drawing.Color]]$Color, [alias ("S")] [nullable[double]] $FontSize, [alias ("FontName")] [string] $FontFamily, [alias ("B")] [nullable[bool]] $Bold, [alias ("I")] [nullable[bool]] $Italic, [alias ("U")] [nullable[UnderlineStyle]] $UnderlineStyle, [alias ('UC')] [nullable[System.Drawing.Color]]$UnderlineColor, [alias ("SA")] [nullable[double]] $SpacingAfter, [alias ("SB")] [nullable[double]] $SpacingBefore, [alias ("SP")] [nullable[double]] $Spacing, [alias ("H")] [nullable[highlight]] $Highlight, [alias ("CA")] [nullable[CapsStyle]] $CapsStyle, [alias ("ST")] [nullable[StrikeThrough]] $StrikeThrough, [alias ("HT")] [nullable[HeadingType]] $HeadingType, [nullable[int]] $PercentageScale , [nullable[Misc]] $Misc , [string] $Language , [nullable[int]]$Kerning , [nullable[bool]]$Hidden , [nullable[int]]$Position , [nullable[single]] $IndentationFirstLine , [nullable[single]] $IndentationHanging , [nullable[Alignment]] $Alignment , [nullable[Direction]] $DirectionFormatting, [nullable[ShadingType]] $ShadingType, [nullable[System.Drawing.Color]]$ShadingColor, [nullable[Script]] $Script, [bool] $Supress = $false) Write-Verbose "Add-WordTableCellValue - Row: $Row Column $Column Value $Value Supress: $Supress" try {$Data = $Table.Rows[$Row].Cells[$Column].Paragraphs[$ParagraphNumber].Append("$Value")} catch { $ErrorMessage = $_.Exception.Message -replace "`n", " " -replace "`r", " " Write-Warning "Add-WordTableCellValue - Failed adding value $Value with error: $ErrorMessage" } $Data = $Data | Set-WordTextColor -Color $Color -Supress $false $Data = $Data | Set-WordTextFontSize -FontSize $FontSize -Supress $false $Data = $Data | Set-WordTextFontFamily -FontFamily $FontFamily -Supress $false $Data = $Data | Set-WordTextBold -Bold $Bold -Supress $false $Data = $Data | Set-WordTextItalic -Italic $Italic -Supress $false $Data = $Data | Set-WordTextUnderlineColor -UnderlineColor $UnderlineColor -Supress $false $Data = $Data | Set-WordTextUnderlineStyle -UnderlineStyle $UnderlineStyle -Supress $false $Data = $Data | Set-WordTextSpacingAfter -SpacingAfter $SpacingAfter -Supress $false $Data = $Data | Set-WordTextSpacingBefore -SpacingBefore $SpacingBefore -Supress $false $Data = $Data | Set-WordTextSpacing -Spacing $Spacing -Supress $false $Data = $Data | Set-WordTextHighlight -Highlight $Highlight -Supress $false $Data = $Data | Set-WordTextCapsStyle -CapsStyle $CapsStyle -Supress $false $Data = $Data | Set-WordTextStrikeThrough -StrikeThrough $StrikeThrough -Supress $false $Data = $Data | Set-WordTextPercentageScale -PercentageScale $PercentageScale -Supress $false $Data = $Data | Set-WordTextSpacing -Spacing $Spacing -Supress $false $Data = $Data | Set-WordTextLanguage -Language $Language -Supress $false $Data = $Data | Set-WordTextKerning -Kerning $Kerning -Supress $false $Data = $Data | Set-WordTextMisc -Misc $Misc -Supress $false $Data = $Data | Set-WordTextPosition -Position $Position -Supress $false $Data = $Data | Set-WordTextHidden -Hidden $Hidden -Supress $false $Data = $Data | Set-WordTextShadingType -ShadingColor $ShadingColor -ShadingType $ShadingType -Supress $false $Data = $Data | Set-WordTextScript -Script $Script -Supress $false $Data = $Data | Set-WordTextHeadingType -HeadingType $HeadingType -Supress $false $Data = $Data | Set-WordTextIndentationFirstLine -IndentationFirstLine $IndentationFirstLine -Supress $false $Data = $Data | Set-WordTextIndentationHanging -IndentationHanging $IndentationHanging -Supress $false $Data = $Data | Set-WordTextAlignment -Alignment $Alignment -Supress $false $Data = $Data | Set-WordTextDirection -Direction $Direction -Supress $false if ($Supress -eq $true) {return} else {return $Data} } function Add-WordTableColumn { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Table, [int] $Count = 1, [nullable[int]] $Index, [ValidateSet('Left', 'Right')] $Direction = 'Left') if ($Direction -eq 'Left') {$ColumnSide = $false} else {$ColumnSide = $true} if ($Table -ne $null) {if ($Index -ne $null) {for ($i = 0; $i -lt $Count; $i++) {$Table.InsertColumn($Index + $i, $ColumnSide)}} else {for ($i = 0; $i -lt $Count; $i++) {$Table.InsertColumn()}}} } function Add-WordTableRow { [CmdletBinding()] param ([Xceed.Words.NET.InsertBeforeOrAfter] $Table, [int] $Count = 1, [nullable[int]] $Index, [bool] $Supress = $false) $List = New-ArrayList if ($Table -ne $null) {if ($Index -ne $null) {for ($i = 0; $i -lt $Count; $i++) {Add-ToArray -List $List -Element $($Table.InsertRow($Index + $i))}} else {for ($i = 0; $i -lt $Count; $i++) {Add-ToArray -List $List -Elemen $($Table.InsertRow())}}} if ($Supress) {return} else {return $List} } function Add-WordTableTitle { [CmdletBinding()] param([Xceed.Words.NET.InsertBeforeOrAfter] $Table, [string[]]$Titles, [int] $MaximumColumns, [alias ("C")] [nullable[System.Drawing.Color]]$Color, [alias ("S")] [nullable[double]] $FontSize, [alias ("FontName")] [string] $FontFamily, [alias ("B")] [nullable[bool]] $Bold, [alias ("I")] [nullable[bool]] $Italic, [alias ("U")] [nullable[UnderlineStyle]] $UnderlineStyle, [alias ('UC')] [nullable[System.Drawing.Color]]$UnderlineColor, [alias ("SA")] [nullable[double]] $SpacingAfter, [alias ("SB")] [nullable[double]] $SpacingBefore , [alias ("SP")] [nullable[double]] $Spacing , [alias ("H")] [nullable[highlight]] $Highlight , [alias ("CA")] [nullable[CapsStyle]] $CapsStyle , [alias ("ST")] [nullable[StrikeThrough]] $StrikeThrough , [alias ("HT")] [nullable[HeadingType]] $HeadingType , [nullable[int]] $PercentageScale , [nullable[Misc]] $Misc , [string] $Language , [nullable[int]]$Kerning , [nullable[bool]]$Hidden , [nullable[int]]$Position , [nullable[single]] $IndentationFirstLine , [nullable[single]] $IndentationHanging , [nullable[Alignment]] $Alignment , [nullable[Direction]] $DirectionFormatting , [nullable[ShadingType]] $ShadingType , [nullable[Script]] $Script , [bool] $Supress = $false) Write-Verbose "Add-WordTableTitle - Title Count $($Titles.Count) Supress $Supress" for ($a = 0; $a -lt $Titles.Count; $a++) { if ($Titles[$a] -is [string]) {$ColumnName = $Titles[$a]} else {$ColumnName = $Titles[$a].Name} Write-Verbose "Add-WordTableTitle - Column Name: $ColumnName Supress $Supress" Write-Verbose "Add-WordTableTitle - Bold $Bold" Add-WordTableCellValue -Table $Table -Row 0 -Column $a -Value $ColumnName -Color $Color -FontSize $FontSize -FontFamily $FontFamily -Bold $Bold -Italic $Italic -UnderlineStyle $UnderlineStyle -UnderlineColor $UnderlineColor -SpacingAfter $SpacingAfter -SpacingBefore $SpacingBefore -Spacing $Spacing -Highlight $Highlight -CapsStyle $CapsStyle -StrikeThrough $StrikeThrough -HeadingType $HeadingType -PercentageScale $PercentageScale -Misc $Misc -Language $Language -Kerning $Kerning -Hidden $Hidden -Position $Position -IndentationFirstLine $IndentationFirstLine -IndentationHanging $IndentationHanging -Alignment $Alignment -DirectionFormatting $DirectionFormatting -ShadingType $ShadingType -Script $Script -Supress $Supress if ($a -eq $($MaximumColumns - 1)) {break} } if ($Supress) {return} else {return $Table} } function Add-WordTabStopPosition { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [single] $HorizontalPosition, [TabStopPositionLeader] $TabStopPositionLeader, [Alignment] $Alignment, [bool] $Supress = $false) if ($Paragraph -eq $null) {$Paragraph = Add-WordParagraph -WordDocument $WordDocument -Supress $False} $data = $Paragraph.InsertTabStopPosition($Alignment, $HorizontalPosition, $TabStopPositionLeader) if ($Supress) {return} else {$data} } function Add-WordText { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Footer] $Footer, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Header] $Header, [alias ("T")] [String[]]$Text, [alias ("C")] [System.Drawing.Color[]]$Color = @(), [alias ("S")] [double[]] $FontSize = @(), [alias ("FontName")] [string[]] $FontFamily = @(), [alias ("B")] [nullable[bool][]] $Bold = @(), [alias ("I")] [nullable[bool][]] $Italic = @(), [alias ("U")] [UnderlineStyle[]] $UnderlineStyle = @(), [alias ('UC')] [System.Drawing.Color[]]$UnderlineColor = @(), [alias ("SA")] [double[]] $SpacingAfter = @(), [alias ("SB")] [double[]] $SpacingBefore = @(), [alias ("SP")] [double[]] $Spacing = @(), [alias ("H")] [highlight[]] $Highlight = @(), [alias ("CA")] [CapsStyle[]] $CapsStyle = @(), [alias ("ST")] [StrikeThrough[]] $StrikeThrough = @(), [alias ("HT")] [HeadingType[]] $HeadingType = @(), [int[]] $PercentageScale = @(), [Misc[]] $Misc = @(), [string[]] $Language = @(), [int[]]$Kerning = @(), [nullable[bool][]]$Hidden = @(), [int[]]$Position = @(), [nullable[bool][]]$NewLine = @(), [single[]] $IndentationFirstLine = @(), [single[]] $IndentationHanging = @(), [Alignment[]] $Alignment = @(), [Direction[]] $Direction = @(), [ShadingType[]] $ShadingType = @(), [System.Drawing.Color[]]$ShadingColor = @(), [Script[]] $Script = @(), [Switch] $ContinueFormatting, [alias ("Append")][Switch] $AppendToExistingParagraph, [bool] $Supress = $false) if ($Alignment -eq $null) {$Alignment = @()} if ($Text.Count -eq 0) {return} if ($Footer -or $Header) { if ($Paragraph -ne $null) { if (-not $AppendToExistingParagraph) { if ($Header) {$NewParagraph = $Header.InsertParagraph()} else {$NewParagraph = $Footer.InsertParagraph()} $Paragraph = $Paragraph.InsertParagraphAfterSelf($NewParagraph) } } else {if ($WordDocument -ne $null) {if ($Header) {$Paragraph = $Header.InsertParagraph()} else {$Paragraph = $Footer.InsertParagraph()}} else {throw 'Both Paragraph and WordDocument are null'}} } else { if ($Paragraph -ne $null) { if (-not $AppendToExistingParagraph) { $NewParagraph = $WordDocument.InsertParagraph() $Paragraph = $Paragraph.InsertParagraphAfterSelf($NewParagraph) } } else {if ($WordDocument -ne $null) {$Paragraph = $WordDocument.InsertParagraph()} else {throw 'Both Paragraph and WordDocument are null'}} } for ($i = 0; $i -lt $Text.Length; $i++) { if ($NewLine[$i] -ne $null -and $NewLine[$i] -eq $true) { if ($i -gt 0) {if ($Paragraph -ne $null) {$Paragraph = $Paragraph.InsertParagraphAfterSelf($Paragraph)} else {$Paragraph = $WordDocument.InsertParagraph()}} $Paragraph = $Paragraph.Append($Text[$i]) } else {$Paragraph = $Paragraph.Append($Text[$i])} if ($ContinueFormatting -eq $true) { Write-Verbose "Add-WordText - ContinueFormatting: $ContinueFormatting Text Count: $($Text.Count)" $Formatting = Set-WordContinueFormatting -Count $Text.Count -Color $Color -FontSize $FontSize -FontFamily $FontFamily -Bold $Bold -Italic $Italic -UnderlineStyle $UnderlineStyle -UnderlineColor $UnderlineColor -SpacingAfter $SpacingAfter -SpacingBefore $SpacingBefore -Spacing $Spacing -Highlight $Highlight -CapsStyle $CapsStyle -StrikeThrough $StrikeThrough -HeadingType $HeadingType -PercentageScale $PercentageScale -Misc $Misc -Language $Language -Kerning $Kerning -Hidden $Hidden -Position $Position -IndentationFirstLine $IndentationFirstLine -IndentationHanging $IndentationHanging -Alignment $Alignment -ShadingType $ShadingType -Script $Script $Color = $Formatting[0] $FontSize = $Formatting[1] $FontFamily = $Formatting[2] $Bold = $Formatting[3] $Italic = $Formatting[4] $UnderlineStyle = $Formatting[5] $UnderlineColor = $Formatting[6] $SpacingAfter = $Formatting[7] $SpacingBefore = $Formatting[8] $Spacing = $Formatting[9] $Highlight = $Formatting[10] $CapsStyle = $Formatting[11] $StrikeThrough = $Formatting[12] $HeadingType = $Formatting[13] $PercentageScale = $Formatting[14] $Misc = $Formatting[15] $Language = $Formatting[16] $Kerning = $Formatting[17] $Hidden = $Formatting[18] $Position = $Formatting[19] $IndentationFirstLine = $Formatting[20] $IndentationHanging = $Formatting[21] $Alignment = $Formatting[22] $ShadingType = $Formatting[24] $Script = $Formatting[25] } $Paragraph = $Paragraph | Set-WordTextColor -Color $Color[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextFontSize -FontSize $FontSize[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextFontFamily -FontFamily $FontFamily[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextBold -Bold $Bold[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextItalic -Italic $Italic[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextUnderlineColor -UnderlineColor $UnderlineColor[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextUnderlineStyle -UnderlineStyle $UnderlineStyle[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextSpacingAfter -SpacingAfter $SpacingAfter[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextSpacingBefore -SpacingBefore $SpacingBefore[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextSpacing -Spacing $Spacing[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextHighlight -Highlight $Highlight[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextCapsStyle -CapsStyle $CapsStyle[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextStrikeThrough -StrikeThrough $StrikeThrough[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextPercentageScale -PercentageScale $PercentageScale[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextSpacing -Spacing $Spacing[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextLanguage -Language $Language[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextKerning -Kerning $Kerning[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextMisc -Misc $Misc[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextPosition -Position $Position[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextHidden -Hidden $Hidden[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextShadingType -ShadingColor $ShadingColor[$i] -ShadingType $ShadingType[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextScript -Script $Script[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextHeadingType -HeadingType $HeadingType[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextIndentationFirstLine -IndentationFirstLine $IndentationFirstLine[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextIndentationHanging -IndentationHanging $IndentationHanging[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextAlignment -Alignment $Alignment[$i] -Supress $false $Paragraph = $Paragraph | Set-WordTextDirection -Direction $Direction[$i] -Supress $false } if ($Supress) {return} else {return $Paragraph} } function Add-WordTOC { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [alias ('BeforeParagraph')][parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [string] $Title = 'Table of contents', [TableOfContentsSwitches[]] $Switches = @(), [alias ('Heading', 'HeadingType')][HeadingType] $HeaderStyle = [HeadingType]::Heading1, [int] $MaxIncludeLevel = 3, [int] $RightTabPos = $null, [bool] $Supress = $false) if ($WordDocument -ne $null) { $TableOfContentSwitch = 0 foreach ($S in $switches) {$TableOfContentSwitch += $s -As [Int]} Write-Verbose $TableOfContentSwitch if ($Paragraph -eq $null) {$toc = $WordDocument.InsertTableOfContents($Title, $TableOfContentSwitch, $HeaderStyle, $MaxIncludeLevel, $RightTabPos)} else {$toc = $WordDocument.InsertTableOfContents($Paragraph, $Title, $TableOfContentSwitch, $HeaderStyle, $MaxIncludeLevel, $RightTabPos)} } if ($Supress -eq $false) {return $Toc} else {return} } function Add-WordTocItem { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [alias('Level')] [ValidateRange(0, 8)] [int] $ListLevel, [alias('ListType')][ListItemType] $ListItemType = [ListItemType]::Bulleted, [alias('Value', 'ListValue')]$Text, [alias ("HT")] [HeadingType] $HeadingType = [HeadingType]::Heading1, [nullable[int]] $StartNumber, [bool]$TrackChanges = $false, [bool]$ContinueNumbering = $true, [bool]$Supress = $false) $List = New-WordListItem -WordDocument $WordDocument -List $null -Text $Text -ListItemType $ListItemType -ContinueNumbering $ContinueNumbering -ListLevel $ListLevel -StartNumber $StartNumber -TrackChanges $TrackChanges $List = Add-WordListItem -WordDocument $WordDocument -List $List $Paragraph = Convert-ListToHeadings -WordDocument $WordDocument -List $List -HeadingType $HeadingType if ($Supress) {return} else {return $Paragraph} } Add-Type -TypeDefinition @" public enum Alignment { left, center, right, both } "@ Add-Type -TypeDefinition @" public enum AutoFit { Contents, Window, ColumnWidth, Fixed } "@ Add-Type -TypeDefinition @" public enum BarDirection { Column, Bar } "@ Add-Type -TypeDefinition @" public enum BarGrouping { Clustered, PercentStacked, Stacked, Standard } "@ Add-Type -TypeDefinition @" public enum BasicShapes { ellipse, triangle, rtTriangle, parallelogram, trapezoid, diamond, pentagon, hexagon, heptagon, octagon, decagon, dodecagon, pie, chord, teardrop, frame, halfFrame, corner, diagStripe, plus, plaque, can, cube, bevel, donut, noSmoking, blockArc, foldedCorner, smileyFace, heart, lightningBolt, sun, moon, cloud, arc, backetPair, bracePair, leftBracket, rightBracket, leftBrace, rightBrace } "@ Add-Type -TypeDefinition @" public enum BlockArrowShapes { rightArrow, leftArrow, upArrow, downArrow, leftRightArrow, upDownArrow, quadArrow, leftRightUpArrow, bentArrow, uturnArrow, leftUpArrow, bentUpArrow, curvedRightArrow, curvedLeftArrow, curvedUpArrow, curvedDownArrow, stripedRightArrow, notchedRightArrow, homePlate, chevron, rightArrowCallout, downArrowCallout, leftArrowCallout, upArrowCallout, leftRightArrowCallout, quadArrowCallout, circularArrow } "@ Add-Type -TypeDefinition @" public enum BorderSize { one, two, three, four, five, six, seven, eight, nine } "@ Add-Type -TypeDefinition @" public enum BorderStyle { Tcbs_none, Tcbs_single, Tcbs_thick, Tcbs_double, Tcbs_dotted, Tcbs_dashed, Tcbs_dotDash, Tcbs_dotDotDash, Tcbs_triple, Tcbs_thinThickSmallGap, Tcbs_thickThinSmallGap, Tcbs_thinThickThinSmallGap, Tcbs_thinThickMediumGap, Tcbs_thickThinMediumGap, Tcbs_thinThickThinMediumGap, Tcbs_thinThickLargeGap, Tcbs_thickThinLargeGap, Tcbs_thinThickThinLargeGap, Tcbs_wave, Tcbs_doubleWave, Tcbs_dashSmallGap, Tcbs_dashDotStroked, Tcbs_threeDEmboss, Tcbs_threeDEngrave, Tcbs_outset, Tcbs_inset, Tcbs_nil } "@ Add-Type -TypeDefinition @" public enum CalloutShapes { wedgeRectCallout, wedgeRoundRectCallout, wedgeEllipseCallout, cloudCallout, borderCallout1, borderCallout2, borderCallout3, accentCallout1, accentCallout2, accentCallout3, callout1, callout2, callout3, accentBorderCallout1, accentBorderCallout2, accentBorderCallout3 } "@ Add-Type -TypeDefinition @" public enum CapsStyle { none, caps, smallCaps } "@ Add-Type -TypeDefinition @" public enum ChartLegendPosition { Top, Bottom, Left, Right, TopRight } "@ Add-Type -TypeDefinition @" public enum DisplayBlanksAs { Gap, Span, Zero } "@ Add-Type -TypeDefinition @" public enum ContainerType { None, TOC, Section, Cell, Table, Header, Footer, Paragraph, Body } "@ function Convert-ListToHeadings { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $List, [alias ("HT")] [HeadingType] $HeadingType = [HeadingType]::Heading1, [bool] $Supress) $ParagraphsWithHeadings = New-ArrayList Write-Verbose "Convert-ListToHeadings - NumID: $($List.NumID)" $Paragraphs = Get-WordParagraphForList -WordDocument $WordDocument -ListID $List.NumID Write-Verbose "Convert-ListToHeadings - List Elements Count: $($Paragraphs.Count)" foreach ($p in $Paragraphs) { Write-Verbose "Convert-ListToHeadings - Loop: $HeadingType" $p.StyleName = $HeadingType Add-ToArray -List $ParagraphsWithHeadings -Element $p } if ($Supress) {return} else {return $ParagraphsWithHeadings} } function Convert-ObjectToProcess { [CmdletBinding()] param ([Array] $DataTable) $ObjectType = $DataTable.GetType().Name Write-Verbose "Convert-ObjectToProcess - GetType Before Conversion: $ObjectType" if ($($DataTable.GetType().BaseType.Name) -eq 'Array' -and $($DataTable.GetType().Name) -eq 'Object[]') { Write-Verbose 'Convert-ObjectToProcess - Converting Array of Objects' $DataTable = $DataTable.ForEach( {[PSCustomObject]$_}) } $ObjectType = $DataTable.GetType().Name Write-Verbose "Convert-ObjectToProcess - Table row count: $($DataTable.Count)" Write-Verbose "Convert-ObjectToProcess - Object Type: $ObjectType" Write-Verbose "Convert-ObjectToProcess - BaseType.Name: $($DataTable.GetType().BaseType.Name)" Write-Verbose "Convert-ObjectToProcess - GetType Before Final Conversion: $ObjectType" If ($ObjectType -eq 'Hashtable' -or $ObjectType -eq 'OrderedDictionary' -or $ObjectType -eq 'PSCustomObject') {Write-Verbose 'Convert-ObjectToProcess - Skipping select for Hashtable / OrderedDictionary / PSCustomObject'} else { if ($ObjectType -eq 'Collection`1' -and $($DataTable.Count) -eq 1) { Write-Verbose 'Convert-ObjectToProcess - Selecting all objects, returning array' $DataTable = [array] ($DataTable | Select-Object *) } else { Write-Verbose 'Convert-ObjectToProcess - Selecting all objects' $DataTable = ($DataTable | Select-Object *) } } $ObjectType = $DataTable.GetType().Name Write-Verbose "Convert-ObjectToProcess - GetType After Conversion: $ObjectType" return , $DataTable } function Copy-WordTableRow { [CmdletBinding()] param ([Xceed.Words.NET.InsertBeforeOrAfter] $Table, $Row, [nullable[int]] $Index) if ($Table -ne $null) {if ($Index -eq $null) {$Table.InsertRow($Row)} else {$Table.InsertRow($Row, $Index)}} } Add-Type -TypeDefinition @" public enum CustomPropertyType { Text, Date, NumberInteger, NumberDecimal, YesOrNo } "@ Add-Type -TypeDefinition @" public enum Direction { LeftToRight, RightToLeft } "@ Add-Type -TypeDefinition @" public enum DocumentTypes { Document, Template } "@ Add-Type -TypeDefinition @" public enum EditRestrictions { none, readOnly, forms, comments, trackedChanges } "@ Add-Type -TypeDefinition @" public enum EditType { ins, del } "@ Add-Type -TypeDefinition @" public enum EquationShapes { mathPlus, mathMinus, mathMultiply, mathDivide, mathEqual, mathNotEqual } "@ Add-Type -TypeDefinition @" public enum FlowchartShapes { flowChartProcess, flowChartAlternateProcess, flowChartDecision, flowChartInputOutput, flowChartPredefinedProcess, flowChartInternalStorage, flowChartDocument, flowChartMultidocument, flowChartTerminator, flowChartPreparation, flowChartManualInput, flowChartManualOperation, flowChartConnector, flowChartOffpageConnector, flowChartPunchedCard, flowChartPunchedTape, flowChartSummingJunction, flowChartOr, flowChartCollate, flowChartSort, flowChartExtract, flowChartMerge, flowChartOnlineStorage, flowChartDelay, flowChartMagneticTape, flowChartMagneticDisk, flowChartMagneticDrum, flowChartDisplay } "@ function Format-WordListItem { param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $List, [ListItemType]$ListType = [ListItemType]::Bulleted, $TextMain, $TextSub, $BehaviourOption) if ($BehaviourOption -eq 0) { Write-Verbose "Add-WordList - This is Name: $($TextMain) With Value $TextSub - Proposed Text: $TextMain and $TextSub on separate line " $List = New-WordListItem -WordDocument $WordDocument -List $List -ListLevel 0 -ListItemType $ListType -ListValue $TextMain foreach ($TextValue in $TextSub) {$List = New-WordListItem -WordDocument $WordDocument -List $List -ListLevel 1 -ListItemType $ListType -ListValue $TextValue} } elseif ($BehaviourOption -eq 1) { $TextSub = $TextSub -Join ", " $Value = "$TextMain - $TextSub" Write-Verbose "Add-WordList - This is Name: $($TextMain) With Value $TextSub - Proposed Text: $Value " $List = New-WordListItem -WordDocument $WordDocument -List $List -ListLevel 0 -ListItemType $ListType -ListValue $Value } return $List } function Get-WordCustomProperty { [CmdletBinding()] param ([Xceed.Words.NET.Container]$WordDocument, [string] $Name) if ($Property -eq $null) {$Data = $WordDocument.CustomProperties.Values} else {$Data = $WordDocument.CustomProperties.$Name.Value} return $Data } function Get-WordDocument { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][alias('Path')][string] $FilePath) $Word = [Xceed.Words.NET.DocX] if ($FilePath -ne '') { if (Test-Path -LiteralPath $FilePath) { try { $WordDocument = $Word::Load($FilePath) $WordDocument | Add-Member -MemberType NoteProperty -Name FilePath -Value $FilePath } catch { $ErrorMessage = $_.Exception.Message Write-Warning "Get-WordDocument - Document: $FilePath Error: $ErrorMessage" } } else { Write-Warning "Get-WordDocument - Document doesn't exists in path $FilePath. Terminating loading word from file." return } } return $WordDocument } function Get-WordFooter { [CmdletBinding()] param ([Xceed.Words.NET.Container]$WordDocument, [ValidateSet('All', 'First', 'Even', 'Odd')][string] $Type = 'All', [bool] $Supress = $false) if ($Type -eq 'All') {$WordDocument.Footers} else {$WordDocument.Footers.$Type} } function Get-WordHeader { [CmdletBinding()] param ([Xceed.Words.NET.Container]$WordDocument, [ValidateSet('All', 'First', 'Even', 'Odd')][string] $Type = 'All', [bool] $Supress = $false) if ($Type -eq 'All') {$WordDocument.Headers} else {$WordDocument.Headers.$Type} } function Get-WordListItemParagraph { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $List, [nullable[int]] $Item, [switch] $LastItem) if ($List -ne $null) { $Count = $List.Items.Count Write-Verbose "Get-WordListItemParagraph - List Count $Count" if ($LastItem) { Write-Verbose "Get-WordListItemParagraph - Last Element $($Count-1)" $Paragraph = $List.Items[$Count - 1] } else { if ($null -ne $Item -and $Item -le $Count) { Write-Verbose "Get-WordListItemParagraph - Returning paragraph for Item Nr: $Item" $Paragraph = $List.Items[$Item] } } } return $Paragraph } function Get-WordPageSettings { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument) $Object = [ordered]@{MarginLeft = $WordDocument.MarginLeft MarginRight = $WordDocument.MarginRight MarginTop = $WordDocument.MarginTop MarginBottom = $WordDocument.MarginBottom PageWidth = $WordDocument.PageWidth PageHeight = $WordDocument.PageHeight Orientation = $WordDocument.PageLayout.Orientation } return $Object } function Get-WordParagraphs { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument) $Paragraphs = @() foreach ($p in $WordDocument.Paragraphs) {$Paragraphs += $p} return $Paragraphs } function Get-WordParagraphForList { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [int] $ListID) $IDs = @() foreach ($p in $WordDocument.Paragraphs) { if ($p.ParagraphNumberProperties -ne $null) { $ListNumber = $p.ParagraphNumberProperties.LastNode.LastAttribute.Value if ($ListNumber -eq $ListID) {$IDs += $p} } } return $Ids } function Get-WordPicture { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [switch] $ListParagraphs, [switch] $ListPictures, [nullable[int]] $PictureID) if ($ListParagraphs -eq $true -and $ListPictures -eq $true) {throw 'Only one option is possible at time (-ListParagraphs or -ListPictures)'} if ($ListParagraphs) { $List = New-ArrayList $Paragraphs = $WordDocument.Paragraphs foreach ($p in $Paragraphs) {if ($p.Pictures -ne $null) {Add-ToArray -List $List -Element $p}} return $List } if ($ListPictures) {return $WordDocument.Pictures} if ($PictureID -ne $null) {return $WordDocument.Pictures[$PictureID]} } function Get-WordSection { [CmdletBinding()] param ([Parameter(Mandatory = $true, ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument) return $WordDocument.Sections } function Get-WordTable { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [switch] $ListTables, [switch] $LastTable, [nullable[int]] $TableID) if ($LastTable) { $Tables = $WordDocument.Tables $Table = $Tables[$Tables.Count - 1] return $Table } if ($ListTables) {return $WordDocument.Tables} if ($TableID -ne $null) {return $WordDocument.Tables[$TableID]} } function Get-WordTableRow { [CmdletBinding()] param ([Xceed.Words.NET.InsertBeforeOrAfter] $Table, [int] $RowNr, [int] $ColumnNr, [int] $ParagraphNr, [switch] $RowsCount) if ($Table -ne $null) { if ($RowsCount) {return $Table.Rows.Count} return $Table.Rows[$RowNr].Cells[$ColumnNr].Paragraphs[$ParagraphNr] } } Add-Type -TypeDefinition @" public enum HeadingType { Heading1, Heading2, Heading3, Heading4, Heading5, Heading6, Heading7, Heading8, Heading9 } "@ Add-Type -TypeDefinition @" public enum Highlight { yellow, green, cyan, magenta, blue, red, darkBlue, darkCyan, darkGreen, darkMagenta, darkRed, darkYellow, darkGray, lightGray, black, none } "@ Add-Type -TypeDefinition @" public enum HorizontalBorderPosition { top, bottom } "@ Add-Type -TypeDefinition @" public enum InsertWhere { AfterSelf, BeforeSelf } "@ Add-Type -TypeDefinition @" public enum Grouping { PercentStacked, Stacked, Standard } "@ Add-Type -TypeDefinition @" public enum LineSpacingType { Line, Before, After } "@ Add-Type -TypeDefinition @" public enum LineSpacingTypeAuto { AutoBefore, AutoAfter, Auto, None } "@ Add-Type -TypeDefinition @" public enum ListItemType { Bulleted, Numbered } "@ Add-Type -TypeDefinition @" public enum MatchFormattingOptions { ExactMatch, SubsetMatch } "@ function Merge-WordDocument { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][alias('Path')][string] $FilePath1, [alias('Append')][string] $FilePath2, [string] $FileOutput, [switch] $OpenDocument, [bool] $Supress = $false) $WordDocument1 = Get-WordDocument -FilePath $FilePath1 $WordDocument2 = Get-WordDocument -FilePath $FilePath2 $WordDocument1.InsertDocument($WordDocument2, $true) $FilePathOutput = Save-WordDocument -WordDocument $WordDocument1 -FilePath $FileOutput -OpenDocument:$OpenDocument if ($Supress) {return} else {return $FilePathOutput} } Add-Type -TypeDefinition @" public enum Misc { none, shadow, outline, outlineShadow, emboss, engrave } "@ function New-WordBlock { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory = $true)][Xceed.Words.NET.Container]$WordDocument, [nullable[bool]] $TocGlobalDefinition, [string] $TocGlobalTitle, [int] $TocGlobalRightTabPos, [TableOfContentsSwitches[]] $TocGlobalSwitches, [nullable[bool]] $TocEnable, [string] $TocText, [int] $TocListLevel, [nullable[ListItemType]] $TocListItemType, [nullable[HeadingType]] $TocHeadingType, [int] $EmptyParagraphsBefore, [int] $EmptyParagraphsAfter, [int] $PageBreaksBefore, [int] $PageBreaksAfter, [string] $Text, [string] $TextNoData, [nullable[Alignment][]] $TextAlignment = [Alignment]::Both, [Object] $TableData, [nullable[TableDesign]] $TableDesign = [TableDesign]::None, [nullable[int]] $TableMaximumColumns = 5, [nullable[bool]] $TableTitleMerge, [string] $TableTitleText, [nullable[Alignment]] $TableTitleAlignment = 'center', [nullable[System.Drawing.Color]] $TableTitleColor = 'Black', [switch] $TableTranspose, [float[]] $TableColumnWidths, [Object] $ListData, [nullable[ListItemType]] $ListType, [string] $ListTextEmpty, [string[]] $ListBuilderContent, [ListItemType[]] $ListBuilderType, [int[]] $ListBuilderLevel, [Object] $TextBasedData, [nullable[Alignment][]] $TextBasedDataAlignment = [Alignment]::Both, [nullable[bool]] $ChartEnable, [string] $ChartTitle, $ChartKeys, $ChartValues, [ChartLegendPosition] $ChartLegendPosition = [ChartLegendPosition]::Bottom, [bool] $ChartLegendOverlay) $WordDocument | New-WordBlockPageBreak -PageBreaks $PageBreaksBefore if ($TocGlobalDefinition) {Add-WordToc -WordDocument $WordDocument -Title $TocGlobalTitle -Switches $TocGlobalSwitches -RightTabPos $TocGlobalRightTabPos -Supress $True} if ($TocEnable) {$TOC = $WordDocument | Add-WordTocItem -Text $TocText -ListLevel $TocListLevel -ListItemType $TocListItemType -HeadingType $TocHeadingType} $WordDocument | New-WordBlockParagraph -EmptyParagraphs $EmptyParagraphsBefore if ($Text) {if ($TableData -or $ListData -or ($ChartEnable -and ($ChartKeys.Count -gt 0) -or ($ChartValues.Count -gt 0)) -or $ListBuilderContent -or (-not $TextNoData)) {$Paragraph = Add-WordText -WordDocument $WordDocument -Paragraph $Paragraph -Text $Text -Alignment $TextAlignment} else {if ($TextNoData) {$Paragraph = Add-WordText -WordDocument $WordDocument -Paragraph $Paragraph -Text $TextNoData -Alignment $TextAlignment}}} if ($TableData -and $TableDesign) { if ($TableMaximumColumns -eq $null) {$TableMaximumColumns = 5} if ($TableColumnWidths) {$Table = Add-WordTable -WordDocument $WordDocument -Paragraph $Paragraph -DataTable $TableData -AutoFit Window -Design $TableDesign -DoNotAddTitle:$TableTitleMerge -MaximumColumns $TableMaximumColumns -Transpose:$TableTranspose -ColumnWidth $TableColumnWidths} else {$Table = Add-WordTable -WordDocument $WordDocument -Paragraph $Paragraph -DataTable $TableData -AutoFit Window -Design $TableDesign -DoNotAddTitle:$TableTitleMerge -MaximumColumns $TableMaximumColumns -Transpose:$TableTranspose} if ($TableTitleMerge) { $Table = Set-WordTableRowMergeCells -Table $Table -RowNr 0 -MergeAll if ($TableTitleText -ne $null) { $TableParagraph = Get-WordTableRow -Table $Table -RowNr 0 -ColumnNr 0 $TableParagraph = Set-WordText -Paragraph $TableParagraph -Text $TableTitleText -Alignment $TableTitleAlignment -Color $TableTitleColor } } } if ($ListData) { if ((Get-ObjectCount $ListData) -gt 0) { Write-Verbose 'New-WordBlock - Adding ListData' $List = Add-WordList -WordDocument $WordDocument -ListType $ListType -Paragraph $Paragraph -ListData $ListData } else { Write-Verbose 'New-WordBlock - Adding ListData - Empty List' $Paragraph = Add-WordText -WordDocument $WordDocument -Paragraph $Paragraph -Text $ListTextEmpty } } if ($ListBuilderContent) { $ListDomainInformation = $null for ($a = 0; $a -lt $ListBuilderContent.Count; $a++) {$ListDomainInformation = $ListDomainInformation | New-WordListItem -WordDocument $WordDocument -ListLevel $ListBuilderLevel[$a] -ListItemType $ListBuilderType[$a] -ListValue $ListBuilderContent[$a]} $Paragraph = Add-WordListItem -WordDocument $WordDocument -Paragraph $Paragraph -List $ListDomainInformation } if ($TextBasedData) {$Paragraph = Add-WordText -WordDocument $WordDocument -Paragraph $Paragraph -Text $TextBasedData -Alignment $TextBasedDataAlignment} if ($ChartEnable) { $WordDocument | New-WordBlockParagraph -EmptyParagraphs 1 if (($ChartKeys.Count -eq 0) -or ($ChartValues.Count -eq 0)) {} else {Add-WordPieChart -WordDocument $WordDocument -ChartName $ChartTitle -Names $ChartKeys -Values $ChartValues -ChartLegendPosition $ChartLegendPosition -ChartLegendOverlay $ChartLegendOverlay} } $WordDocument | New-WordBlockParagraph -EmptyParagraphs $EmptyParagraphsAfter $WordDocument | New-WordBlockPageBreak -PageBreaks $PageBreaksAfter } function New-WordBlockList { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory = $true)][Xceed.Words.NET.Container]$WordDocument, [bool] $TocEnable, [string] $TocText, [int] $TocListLevel, [ListItemType] $TocListItemType, [HeadingType] $TocHeadingType, [int] $EmptyParagraphsBefore, [int] $EmptyParagraphsAfter, [string] $Text, [string] $TextListEmpty, [Object] $ListData, [ListItemType] $ListType) if ($TocEnable) {$TOC = $WordDocument | Add-WordTocItem -Text $TocText -ListLevel $TocListLevel -ListItemType $TocListItemType -HeadingType $TocHeadingType} $WordDocument | New-WordBlockParagraph -EmptyParagraphs $EmptyParagraphsBefore $Paragraph = Add-WordText -WordDocument $WordDocument -Paragraph $Paragraph -Text $Text if ((Get-ObjectCount $ListData) -gt 0) {$List = Add-WordList -WordDocument $WordDocument -ListType $ListType -Paragraph $Paragraph -ListData $ListData} else {$Paragraph = Add-WordText -WordDocument $WordDocument -Paragraph $Paragraph -Text $TextListEmpty} $WordDocument |New-WordBlockParagraph -EmptyParagraphs $EmptyParagraphsAfter } function New-WordBlockPageBreak { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory = $true)][Xceed.Words.NET.Container]$WordDocument, [int] $PageBreaks, [bool] $Supress) $i = 0 While ($i -lt $PageBreaks) { Write-Verbose "New-WordBlockPageBreak - PageBreak $i" $WordDocument | Add-WordPageBreak -Supress $True $i++ } } function New-WordBlockParagraph { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory = $true)][Xceed.Words.NET.Container]$WordDocument, [int] $EmptyParagraphs) $i = 0 While ($i -lt $EmptyParagraphs) { Write-Verbose "New-WordBlockList - EmptyParagraphs $i" $Paragraph = Add-WordParagraph -WordDocument $WordDocument $i++ } } function New-WordBlockTable { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory = $true)][Xceed.Words.NET.Container]$WordDocument, [bool] $TocEnable, [string] $TocText, [int] $TocListLevel, [ListItemType] $TocListItemType, [HeadingType] $TocHeadingType, [int] $EmptyParagraphsBefore, [int] $EmptyParagraphsAfter, [int] $PageBreaksBefore, [int] $PageBreaksAfter, [string] $Text, [Object] $TableData, [nullable[TableDesign]] $TableDesign, [int] $TableMaximumColumns = 5, [nullable[bool]] $TableTitleMerge, [string] $TableTitleText, [nullable[Alignment]] $TableTitleAlignment = 'center', [nullable[System.Drawing.Color]] $TableTitleColor = 'Black', [switch] $TableTranspose, [nullable[bool]] $ChartEnable, [string] $ChartTitle, $ChartKeys, $ChartValues, [ChartLegendPosition] $ChartLegendPosition = [ChartLegendPosition]::Bottom, [bool] $ChartLegendOverlay) $WordDocument | New-WordBlockPageBreak -PageBreaks $PageBreaksBefore if ($TocEnable) {$TOC = $WordDocument | Add-WordTocItem -Text $TocText -ListLevel $TocListLevel -ListItemType $TocListItemType -HeadingType $TocHeadingType} $WordDocument | New-WordBlockParagraph -EmptyParagraphs $EmptyParagraphsBefore $Paragraph = Add-WordText -WordDocument $WordDocument -Paragraph $Paragraph -Text $Text if ($TableData) { $Table = Add-WordTable -WordDocument $WordDocument -Paragraph $Paragraph -DataTable $TableData -AutoFit Window -Design $TableDesign -DoNotAddTitle:$TableTitleMerge -MaximumColumns $TableMaximumColumns -Transpose:$TableTranspose if ($TableTitleMerge) { $Table = Set-WordTableRowMergeCells -Table $Table -RowNr 0 -MergeAll if ($TableTitleText -ne $null) { $TableParagraph = Get-WordTableRow -Table $Table -RowNr 0 -ColumnNr 0 $TableParagraph = Set-WordText -Paragraph $TableParagraph -Text $TableTitleText -Alignment $TableTitleAlignment -Color $TableTitleColor } } } if ($ChartEnable) { $WordDocument | New-WordBlockParagraph -EmptyParagraphs 1 Add-WordPieChart -WordDocument $WordDocument -ChartName $ChartTitle -Names $ChartKeys -Values $ChartValues -ChartLegendPosition $ChartLegendPosition -ChartLegendOverlay $ChartLegendOverlay } $WordDocument | New-WordBlockParagraph -EmptyParagraphs $EmptyParagraphsAfter $WordDocument | New-WordBlockPageBreak -PageBreaks $PageBreaksAfter } function New-WordDocument { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][alias('Path')][string] $FilePath = '') $Word = [Xceed.Words.NET.DocX] $WordDocument = $Word::Create($FilePath) $WordDocument | Add-Member -MemberType NoteProperty -Name FilePath -Value $FilePath return $WordDocument } function New-WordListItem { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $List, [alias('Level')] [ValidateRange(0, 8)] [int] $ListLevel, [alias('ListType')][ListItemType] $ListItemType = [ListItemType]::Bulleted, [alias('Value', 'ListValue')]$Text, [nullable[int]] $StartNumber, [bool]$TrackChanges = $false, [bool]$ContinueNumbering = $false, [bool]$Supress = $false) if ($List -eq $null) { $List = $WordDocument.AddList($Text, $ListLevel, $ListItemType, $StartNumber, $TrackChanges, $ContinueNumbering) $Paragraph = $List.Items[$List.Items.Count - 1] } else { $List = $WordDocument.AddListItem($List, $Text, $ListLevel, $ListItemType, $StartNumber, $TrackChanges, $ContinueNumbering) $Paragraph = $List.Items[$List.Items.Count - 1] } Write-Verbose "Add-WordListItem - ListType Value: $Text Name: $($List.GetType().Name) - BaseType: $($List.GetType().BaseType)" return $List }function New-WordListItem { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $List, [alias('Level')] [ValidateRange(0, 8)] [int] $ListLevel, [alias('ListType')][ListItemType] $ListItemType = [ListItemType]::Bulleted, [alias('Value', 'ListValue')]$Text, [nullable[int]] $StartNumber, [bool]$TrackChanges = $false, [bool]$ContinueNumbering = $false, [bool]$Supress = $false) if ($List -eq $null) { $List = $WordDocument.AddList($Text, $ListLevel, $ListItemType, $StartNumber, $TrackChanges, $ContinueNumbering) $Paragraph = $List.Items[$List.Items.Count - 1] } else { $List = $WordDocument.AddListItem($List, $Text, $ListLevel, $ListItemType, $StartNumber, $TrackChanges, $ContinueNumbering) $Paragraph = $List.Items[$List.Items.Count - 1] } Write-Verbose "Add-WordListItem - ListType Value: $Text Name: $($List.GetType().Name) - BaseType: $($List.GetType().BaseType)" return $List } function New-WordTable { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [int] $NrRows, [int] $NrColumns, [bool] $Supress = $false) Write-Verbose "New-WordTable - Paragraph $Paragraph" Write-Verbose "New-WordTable - NrRows $NrRows NrColumns $NrColumns Supress $supress" if ($Paragraph -eq $null) {$WordTable = $WordDocument.InsertTable($NrRows, $NrColumns)} else { $TableDefinition = $WordDocument.AddTable($NrRows, $NrColumns) $WordTable = $Paragraph.InsertTableAfterSelf($TableDefinition) } if ($Supress) {return} else {return $WordTable} } function New-WordTableBorder { [CmdletBinding()] param ([BorderStyle] $BorderStyle, [BorderSize] $BorderSize, [int] $BorderSpace, [System.Drawing.Color] $BorderColor) $Border = New-Object -TypeName Xceed.Words.NET.Border -ArgumentList $BorderStyle, $BorderSize, $BorderSpace, $BorderColor return $Border } Add-Type -TypeDefinition @" public enum Orientation { Portrait, Landscape } "@ Add-Type -TypeDefinition @" public enum PageNumberFormat { normal, roman } "@ function Set-WordMargins { param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [nullable[single]] $MarginLeft, [nullable[single]] $MarginRight, [nullable[single]] $MarginTop, [nullable[single]] $MarginBottom) if ($MarginLeft -ne $null) {$WordDocument.MarginLeft = $MarginLeft} if ($MarginRight -ne $null) {$WordDocument.MarginRight = $MarginRight} if ($MarginTop -ne $null) {$WordDocument.MarginTop = $MarginTop} if ($MarginBottom -ne $null) {$WordDocument.MarginBottom = $MarginBottom} } function Set-WordPageSize { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [nullable[single]] $PageWidth, [nullable[single]] $PageHeight) if ($PageWidth -ne $null) {$WordDocument.PageWidth = $PageWidth} if ($PageHeight -ne $null) {$WordDocument.PageHeight = $PageHeight} } function Set-WordTextFontSize { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [alias ("S")] [nullable[double]] $FontSize, [bool] $Supress = $false) if ($Paragraph -ne $null -and $FontSize -ne $null) {$Paragraph = $Paragraph.FontSize($FontSize)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextColor { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [alias ("C")] [nullable[System.Drawing.Color]] $Color, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Color -ne $null) {$Paragraph = $Paragraph.Color($Color)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextBold { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[bool]] $Bold, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Bold -ne $null -and $Bold -eq $true) {$Paragraph = $Paragraph.Bold()} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextItalic { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[bool]] $Italic, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Italic -ne $null -and $Italic -eq $true) {$Paragraph = $Paragraph.Italic()} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextFontFamily { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [string] $FontFamily, [bool] $Supress = $false) if ($Paragraph -ne $null -and $FontFamily -ne $null -and $FontFamily -ne '') {$Paragraph = $Paragraph.Font($FontFamily)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextUnderlineStyle { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[UnderlineStyle]] $UnderlineStyle, [bool] $Supress = $false) if ($Paragraph -ne $null -and $UnderlineStyle -ne $null) {$Paragraph = $Paragraph.UnderlineStyle($UnderlineStyle)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextUnderlineColor { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[System.Drawing.Color]] $UnderlineColor, [bool] $Supress = $false) if ($Paragraph -ne $null -and $UnderlineColor -ne $null) {$Paragraph = $Paragraph.UnderlineColor($UnderlineColor)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextSpacingAfter { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[double]] $SpacingAfter, [bool] $Supress = $false) if ($Paragraph -ne $null -and $SpacingAfter -ne $null) {$Paragraph = $Paragraph.SpacingAfter($SpacingAfter)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextSpacingBefore { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[double]] $SpacingBefore, [bool] $Supress = $false) if ($Paragraph -ne $null -and $SpacingBefore -ne $null) {$Paragraph = $Paragraph.SpacingBefore($SpacingBefore)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextSpacing { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[double]] $Spacing, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Spacing -ne $null) {$Paragraph = $Paragraph.Spacing($Spacing)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextHighlight { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[Highlight]] $Highlight, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Highlight -ne $null) {$Paragraph = $Paragraph.Highlight($Highlight)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextCapsStyle { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[CapsStyle]] $CapsStyle, [bool] $Supress = $false) if ($Paragraph -ne $null -and $CapsStyle -ne $null) {$Paragraph = $Paragraph.CapsStyle($CapsStyle)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextStrikeThrough { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[StrikeThrough]] $StrikeThrough, [bool] $Supress = $false) if ($Paragraph -ne $null -and $StrikeThrough -ne $null) {$Paragraph = $Paragraph.StrikeThrough($StrikeThrough)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextShadingType { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[ShadingType]] $ShadingType, [nullable[System.Drawing.Color]] $ShadingColor, [bool] $Supress = $false) if ($Paragraph -ne $null -and $ShadingType -ne $null -and $ShadingColor -ne $null) {$Paragraph = $Paragraph.Shading($ShadingColor, $ShadingType)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextPercentageScale { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[int]]$PercentageScale, [bool] $Supress = $false) if ($Paragraph -ne $null -and $PercentageScale -ne $null) {$Paragraph = $Paragraph.PercentageScale($PercentageScale)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextLanguage { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [string]$Language, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Language -ne $null -and $Language -ne '') { $Culture = [System.Globalization.CultureInfo]::GetCultureInfo($Language) $Paragraph = $Paragraph.Culture($Culture) } if ($Supress) {return} else {return $Paragraph} } function Set-WordTextKerning { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[int]] $Kerning, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Kerning -ne $null) {$Paragraph = $Paragraph.Kerning($Kerning)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextMisc { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[Misc]] $Misc, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Misc -ne $null) {$Paragraph = $Paragraph.Misc($Misc)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextPosition { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[int]]$Position, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Position -ne $null) {$Paragraph = $Paragraph.Position($Position)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextHidden { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[bool]] $Hidden, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Hidden -ne $null) {$Paragraph = $Paragraph.Hidden($Hidden)} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextHeadingType { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[HeadingType]] $HeadingType, [bool] $Supress = $false) if ($Paragraph -ne $null -and $HeadingType -ne $null) { Write-Verbose "Set-WordTextHeadingType - Setting StyleName to $StyleName" $Paragraph.StyleName = $HeadingType } if ($Supress) {return} else {return $Paragraph} } function Set-WordTextIndentationFirstLine { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[single]] $IndentationFirstLine, [bool] $Supress = $false) if ($Paragraph -ne $null -and $IndentationFirstLine -ne $null) {$Paragraph.IndentationFirstLine = $IndentationFirstLine} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextAlignment { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[Alignment]] $Alignment, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Alignment -ne $null) {$Paragraph.Alignment = $Alignment} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextIndentationHanging { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[single]] $IndentationHanging, [bool] $Supress = $false) if ($Paragraph -ne $null -and $IndentationHanging -ne $null) {$Paragraph.IndentationHanging = $IndentationHanging} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextDirection { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[Direction]] $Direction, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Direction -ne $null) {$Paragraph.Direction = $Direction} if ($Supress) {return} else {return $Paragraph} } function Set-WordTextScript { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[Script]] $Script, [bool] $Supress = $false) if ($Paragraph -ne $null -and $Script -ne $null) {$Paragraph = $Paragraph.Script($Script)} if ($Supress) {return} else {return $Paragraph} } function Remove-WordParagraph { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [bool] $TrackChanges) $Paragraph.Remove($TrackChanges) } function Set-WordTableRowMergeCells { [CmdletBinding()] param([Xceed.Words.NET.InsertBeforeOrAfter] $Table, [nullable[int]] $RowNr, [nullable[int]] $ColumnNrStart, [nullable[int]] $ColumnNrEnd, [switch] $MergeAll, [switch] $TrackChanges, [switch] $TextMerge, [string] $Separator = ' ', [bool] $Supress = $false) if ($Table) { if ($MergeAll -and $RowNr -ne $null) { $CellsCount = $Table.Rows[$RowNr].Cells.Count $Table.Rows[$RowNr].MergeCells(0, $CellsCount) for ($paragraph = 1; $paragraph -le $Table.Rows[$RowNr].Paragraphs.Count; $paragraph++) {$Table.Rows[$RowNr].Paragraphs[$paragraph].Remove($TrackChanges)} } elseif ($RowNr -ne $null -and $ColumnNrStart -ne $null -and $ColumnNrEnd -ne $null) { $CurrentParagraphCount = $Table.Rows[$RowNr].Cells[$ColumnNrStart].Paragraphs.Count $Table.Rows[$RowNr].MergeCells($ColumnNrStart, $ColumnNrEnd) if ($TextMerge) {[string] $Texts = foreach ($Paragraph in $Table.Rows[$RowNr].Cells[$ColumnNrStart].Paragraphs | Select-Object -Skip ($CurrentParagraphCount - 1)) {$Paragraph.Text} -join $Separator} foreach ($Paragraph in $Table.Rows[$RowNr].Cells[$ColumnNrStart].Paragraphs | Select-Object -Skip $CurrentParagraphCount) {$Paragraph.Remove($TrackChanges)} if ($TextMerge) {Set-WordTextText -Paragraph $Table.Rows[$RowNr].Cells[$ColumnNrStart].Paragraphs[$CurrentParagraphCount - 1] -Text $Texts -Supress $True} } } if ($Supress) {return} else {return $Table} } function Set-WordTableCell { [CmdletBinding()] param ([Xceed.Words.NET.InsertBeforeOrAfter] $Table, [nullable[int]] $RowNr, [nullable[int]] $ColumnNr, [System.Drawing.Color] $FillColor, [System.Drawing.Color] $ShadingColor, [bool] $Supress = $false) $Table = Set-WordTableCellFillColor -Table $Table -RowNr $RowNr -ColumnNr $ColumnNr -FillColor $FillColor -Supress $false $Table = Set-WordTableCellShadingColor -Table $Table -RowNr $RowNr -ColumnNr $ColumnNr -ShadingColor $ShadingColor -Supress $false if ($Supress) {return} else {return $Table} } function Set-WordTableCellFillColor { [CmdletBinding()] param ([Xceed.Words.NET.InsertBeforeOrAfter] $Table, [nullable[int]] $RowNr, [nullable[int]] $ColumnNr, [nullable[System.Drawing.Color]] $FillColor, [bool] $Supress = $false) if ($Table -ne $null -and $RowNr -ne $null -and $ColumnNr -ne $null -and $FillColor -ne $null) { $Cell = $Table.Rows[$RowNr].Cells[$ColumnNr] $Cell.FillColor = $FillColor } if ($Supress) {return} else {return $Table} } function Set-WordTableCellShadingColor { [CmdletBinding()] param ([Xceed.Words.NET.InsertBeforeOrAfter] $Table, [nullable[int]] $RowNr, [nullable[int]] $ColumnNr, [nullable[System.Drawing.Color]] $ShadingColor, [bool] $Supress = $false) if ($Table -ne $null -and $RowNr -ne $null -and $ColumnNr -ne $null -and $ShadingColor -ne $null) { $Cell = $Table.Rows[$RowNr].Cells[$ColumnNr] $Cell.Shading = $ShadingColor } if ($Supress) {return} else {return $Table} } function Get-ColorFromARGB { param([int] $A, [int] $R, [int] $G, [int] $B) return [system.drawing.color]::FromArgb($A, $R, $G, $B) } Add-Type -TypeDefinition @" public enum RectangleShapes { rect, roundRect, snip1Rect, snip2SameRect, snip2DiagRect, snipRoundRect, round1Rect, round2SameRect, round2DiagRect } "@ function Remove-WordPicture { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [int] $PictureID, [bool] $Supress) if ($Paragraph.Pictures[$PictureID] -ne $null) {$Paragraph.Pictures[$PictureID].Remove()} if ($supress) {return} else {return $Paragraph} } function Remove-WordTable { [CmdletBinding()] param ([Xceed.Words.NET.InsertBeforeOrAfter] $Table) if ($Table -ne $null) {$Table.Remove()} } function Remove-WordTableColumn { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Table, [int] $Count = 1, [nullable[int]] $Index) if ($Table -ne $null) {if ($Index -ne $null) {for ($i = 0; $i -lt $Count; $i++) {$Table.RemoveColumn($Index + $i)}} else {for ($i = 0; $i -lt $Count; $i++) {$Table.RemoveColumn()}}} } function Remove-WordTableRow { [CmdletBinding()] param ([Xceed.Words.NET.InsertBeforeOrAfter] $Table, [int] $Count = 1, [nullable[int]] $Index, [bool] $Supress) if ($Table -ne $null) {if ($Index -ne $null) {for ($i = 0; $i -lt $Count; $i++) {$Table.RemoveRow($Index + $i)}} else {for ($i = 0; $i -lt $Count; $i++) {$Table.RemoveRow()}}} if ($Supress) {return} else {return $Table} } function Remove-WordText { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [int] $Index = 0, [int] $Count = $($Paragraph.Text.Length), [bool] $TrackChanges, [bool] $RemoveEmptyParagraph, [bool] $Supress = $false) if ($Paragraph -ne $null) { Write-Verbose "Remove-WordText - Current text $($Paragraph.Text) " Write-Verbose "Remove-WordText - Removing from $Index to $Count - Paragraph Text Count: $($Paragraph.Text.Length)" if ($Count -ne 0) {$Paragraph.RemoveText($Index, $Count, $TrackChanges, $RemoveEmptyParagraph)} } if ($Supress) {return} else {return $Paragraph} } Add-Type -TypeDefinition @" public enum RunTextType { Text, DelText } "@ function Save-WordDocument { [CmdletBinding()] param ([alias('Document')][parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory = $false)][Xceed.Words.NET.Container]$WordDocument, [alias('Path')][string] $FilePath, [string] $Language, [switch] $KillWord, [switch] $OpenDocument, [bool] $Supress = $false) if ($Language) { Write-Verbose -Message "Save-WordDocument - Setting Language to $Language" $Paragraphs = Get-WordParagraphs -WordDocument $WordDocument foreach ($p in $Paragraphs) {Set-WordParagraph -Paragraph $p -Language $Language -Supress $True} } if (($KillWord) -and ($FilePath)) { $FileName = Split-Path $FilePath -leaf Write-Verbose -Message "Save-WordDocument - Killing Microsoft Word with text $FileName" $Process = Stop-Process -Name "$FileName*" -Confirm:$false -PassThru Write-Verbose -Message "Save-WordDocument - Killed Microsoft Word: $FileName" } if (-not $FilePath) { try { $FilePath = $WordDocument.FilePath Write-Verbose -Message "Save-WordDocument - Saving document (Save: $FilePath)" $Data = $WordDocument.Save() } catch { $ErrorMessage = $_.Exception.Message if ($ErrorMessage -like "*The process cannot access the file*because it is being used by another process.*") { $FilePath = "$($([System.IO.Path]::GetTempFileName()).Split('.')[0]).docx" Write-Warning -Message "Couldn't save file as it was in use. Trying different name $FilePath" $Data = $WordDocument.SaveAs($FilePath) } } } else { try { Write-Verbose "Save-WordDocument - Saving document (Save AS: $FilePath)" $Data = $WordDocument.SaveAs($FilePath) } catch { $ErrorMessage = $_.Exception.Message if ($ErrorMessage -like "*The process cannot access the file*because it is being used by another process.*") { $FilePath = "$($([System.IO.Path]::GetTempFileName()).Split('.')[0]).docx" Write-Warning -Message "Couldn't save file as it was in use. Trying different name $FilePath" $Data = $WordDocument.SaveAs($FilePath) } } } If ($OpenDocument) {if (($FilePath -ne '') -and (Test-Path -LiteralPath $FilePath)) {Invoke-Item -Path $FilePath} else {Write-Warning -Message "Couldn't open file as it doesn't exists - $FilePath"}} if ($Supress) {return} else {return $FilePath} } Add-Type -TypeDefinition @" public enum Script { superscript, subscript, none } "@ Add-Type -TypeDefinition @" public enum SectionBreakType { defaultNextPage, evenPage, oddPage, continuous } "@ function Set-WordContinueFormatting { param([int] $Count, [alias ("C")] [System.Drawing.Color[]]$Color = @(), [alias ("S")] [double[]] $FontSize = @(), [alias ("FontName")] [string[]] $FontFamily = @(), [alias ("B")] [nullable[bool][]] $Bold = @(), [alias ("I")] [nullable[bool][]] $Italic = @(), [alias ("U")] [UnderlineStyle[]] $UnderlineStyle = @(), [alias ('UC')] [System.Drawing.Color[]]$UnderlineColor = @(), [alias ("SA")] [double[]] $SpacingAfter = @(), [alias ("SB")] [double[]] $SpacingBefore = @(), [alias ("SP")] [double[]] $Spacing = @(), [alias ("H")] [highlight[]] $Highlight = @(), [alias ("CA")] [CapsStyle[]] $CapsStyle = @(), [alias ("ST")] [StrikeThrough[]] $StrikeThrough = @(), [alias ("HT")] [HeadingType[]] $HeadingType = @(), [int[]] $PercentageScale = @(), [Misc[]] $Misc = @(), [string[]] $Language = @(), [int[]]$Kerning = @(), [nullable[bool][]]$Hidden = @(), [int[]]$Position = @(), [single[]] $IndentationFirstLine = @(), [single[]] $IndentationHanging = @(), [Alignment[]] $Alignment = @(), [Direction[]] $DirectionFormatting = @(), [ShadingType[]] $ShadingType = @(), [Script[]] $Script = @()) for ($RowNr = 0; $RowNr -lt $Count; $RowNr++) { Write-Verbose "Set-WordContinueFormatting - RowNr: $RowNr / $Count" if ($null -eq $Color[$RowNr] -and $null -ne $Color[$RowNr - 1]) {$Color += $Color[$RowNr - 1]} if ($null -eq $FontSize[$RowNr] -and $null -ne $FontSize[$RowNr - 1]) {$FontSize += $FontSize[$RowNr - 1]} if ($null -eq $FontFamily[$RowNr] -and $null -ne $FontFamily[$RowNr - 1]) {$FontFamily += $FontFamily[$RowNr - 1]} if ($null -eq $Bold[$RowNr] -and $null -ne $Bold[$RowNr - 1]) {$Bold += $Bold[$RowNr - 1]} if ($null -eq $Italic[$RowNr] -and $null -ne $Italic[$RowNr - 1]) {$Italic += $Italic[$RowNr - 1]} if ($null -eq $SpacingAfter[$RowNr] -and $null -ne $SpacingAfter[$RowNr - 1]) {$SpacingAfter += $SpacingAfter[$RowNr - 1]} if ($null -eq $SpacingBefore[$RowNr] -and $null -ne $SpacingBefore[$RowNr - 1]) {$SpacingBefore += $SpacingBefore[$RowNr - 1]} if ($null -eq $Spacing[$RowNr] -and $null -ne $Spacing[$RowNr - 1]) {$Spacing += $Spacing[$RowNr - 1]} if ($null -eq $Highlight[$RowNr] -and $null -ne $Highlight[$RowNr - 1]) {$Highlight += $Highlight[$RowNr - 1]} if ($null -eq $CapsStyle[$RowNr] -and $null -ne $CapsStyle[$RowNr - 1]) {$CapsStyle += $CapsStyle[$RowNr - 1]} if ($null -eq $StrikeThrough[$RowNr] -and $null -ne $StrikeThrough[$RowNr - 1]) {$StrikeThrough += $StrikeThrough[$RowNr - 1]} if ($null -eq $HeadingType[$RowNr] -and $null -ne $HeadingType[$RowNr - 1]) {$HeadingType += $HeadingType[$RowNr - 1]} if ($null -eq $PercentageScale[$RowNr] -and $null -ne $PercentageScale[$RowNr - 1]) {$PercentageScale += $PercentageScale[$RowNr - 1]} if ($null -eq $Misc[$RowNr] -and $null -ne $Misc[$RowNr - 1]) {$Misc += $Misc[$RowNr - 1]} if ($null -eq $Language[$RowNr] -and $null -ne $Language[$RowNr - 1]) {$Language += $Language[$RowNr - 1]} if ($null -eq $Kerning[$RowNr] -and $null -ne $Kerning[$RowNr - 1]) {$Kerning += $Kerning[$RowNr - 1]} if ($null -eq $Hidden[$RowNr] -and $null -ne $Hidden[$RowNr - 1]) {$Hidden += $Hidden[$RowNr - 1]} if ($null -eq $Position[$RowNr] -and $null -ne $Position[$RowNr - 1]) {$Position += $Position[$RowNr - 1]} if ($null -eq $IndentationFirstLine[$RowNr] -and $null -ne $IndentationFirstLine[$RowNr - 1]) {$IndentationFirstLine += $IndentationFirstLine[$RowNr - 1]} if ($null -eq $IndentationHanging[$RowNr] -and $null -ne $IndentationHanging[$RowNr - 1]) {$IndentationHanging += $IndentationHanging[$RowNr - 1]} if ($null -eq $Alignment[$RowNr] -and $null -ne $Alignment[$RowNr - 1]) {$Alignment += $Alignment[$RowNr - 1]} if ($null -eq $DirectionFormatting[$RowNr] -and $null -ne $DirectionFormatting[$RowNr - 1]) {$DirectionFormatting += $DirectionFormatting[$RowNr - 1]} if ($null -eq $ShadingType[$RowNr] -and $null -ne $ShadingType[$RowNr - 1]) {$ShadingType += $ShadingType[$RowNr - 1]} if ($null -eq $Script[$RowNr] -and $null -ne $Script[$RowNr - 1]) {$Script += $Script[$RowNr - 1]} } Write-Verbose "Set-WordContinueFormatting - Alignment: $Alignment" return @($Color, $FontSize, $FontFamily, $Bold, $Italic, $UnderlineStyle, $UnderlineColor, $SpacingAfter, $SpacingBefore, $Spacing, $Highlight, $CapsStyle, $StrikeThrough, $HeadingType, $PercentageScale, $Misc, $Language, $Kerning, $Hidden, $Position, $IndentationFirstLine, $IndentationHanging, $Alignment, $DirectionFormatting, $ShadingType, $Script) } function Set-WordHyperLink { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)] [Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)] [Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [Xceed.Words.NET.DocXElement] $Value, [bool] $Supress = $false) $Data = $Paragraph.InsertHyperlink($Value) if ($Supress -eq $false) {return $Data} else {return} } function Set-WordList { param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container] $WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $List, [int] $ParagraphNumber = 0, [alias ("C")] [nullable[System.Drawing.Color]]$Color, [alias ("S")] [nullable[double]] $FontSize, [alias ("FontName")] [string] $FontFamily, [alias ("B")] [nullable[bool]] $Bold, [alias ("I")] [nullable[bool]] $Italic, [alias ("U")] [nullable[UnderlineStyle]] $UnderlineStyle, [alias ('UC')] [nullable[System.Drawing.Color]]$UnderlineColor, [alias ("SA")] [nullable[double]] $SpacingAfter, [alias ("SB")] [nullable[double]] $SpacingBefore, [alias ("SP")] [nullable[double]] $Spacing, [alias ("H")] [nullable[highlight]] $Highlight, [alias ("CA")] [nullable[CapsStyle]] $CapsStyle, [alias ("ST")] [nullable[StrikeThrough]] $StrikeThrough, [alias ("HT")] [nullable[HeadingType]] $HeadingType, [nullable[int]] $PercentageScale , [nullable[Misc]] $Misc , [string] $Language , [nullable[int]]$Kerning , [nullable[bool]]$Hidden , [nullable[int]]$Position , [nullable[single]] $IndentationFirstLine , [nullable[single]] $IndentationHanging , [nullable[Alignment]] $Alignment , [nullable[Direction]] $DirectionFormatting, [nullable[ShadingType]] $ShadingType, [nullable[System.Drawing.Color]]$ShadingColor, [nullable[Script]] $Script, [bool] $Supress = $false) foreach ($Data in $List.Items) { $Data = $Data | Set-WordTextColor -Color $Color -Supress $false $Data = $Data | Set-WordTextFontSize -FontSize $FontSize -Supress $false $Data = $Data | Set-WordTextFontFamily -FontFamily $FontFamily -Supress $false $Data = $Data | Set-WordTextBold -Bold $Bold -Supress $false $Data = $Data | Set-WordTextItalic -Italic $Italic -Supress $false $Data = $Data | Set-WordTextUnderlineColor -UnderlineColor $UnderlineColor -Supress $false $Data = $Data | Set-WordTextUnderlineStyle -UnderlineStyle $UnderlineStyle -Supress $false $Data = $Data | Set-WordTextSpacingAfter -SpacingAfter $SpacingAfter -Supress $false $Data = $Data | Set-WordTextSpacingBefore -SpacingBefore $SpacingBefore -Supress $false $Data = $Data | Set-WordTextSpacing -Spacing $Spacing -Supress $false $Data = $Data | Set-WordTextHighlight -Highlight $Highlight -Supress $false $Data = $Data | Set-WordTextCapsStyle -CapsStyle $CapsStyle -Supress $false $Data = $Data | Set-WordTextStrikeThrough -StrikeThrough $StrikeThrough -Supress $false $Data = $Data | Set-WordTextPercentageScale -PercentageScale $PercentageScale -Supress $false $Data = $Data | Set-WordTextSpacing -Spacing $Spacing -Supress $false $Data = $Data | Set-WordTextLanguage -Language $Language -Supress $false $Data = $Data | Set-WordTextKerning -Kerning $Kerning -Supress $false $Data = $Data | Set-WordTextMisc -Misc $Misc -Supress $false $Data = $Data | Set-WordTextPosition -Position $Position -Supress $false $Data = $Data | Set-WordTextHidden -Hidden $Hidden -Supress $false $Data = $Data | Set-WordTextShadingType -ShadingColor $ShadingColor -ShadingType $ShadingType -Supress $false $Data = $Data | Set-WordTextScript -Script $Script -Supress $false $Data = $Data | Set-WordTextHeadingType -HeadingType $HeadingType -Supress $false $Data = $Data | Set-WordTextIndentationFirstLine -IndentationFirstLine $IndentationFirstLine -Supress $false $Data = $Data | Set-WordTextIndentationHanging -IndentationHanging $IndentationHanging -Supress $false $Data = $Data | Set-WordTextAlignment -Alignment $Alignment -Supress $false $Data = $Data | Set-WordTextDirection -Direction $Direction -Supress $false } if ($Supress) {return} else {return $List} } function Set-WordOrientation { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [alias ("PageLayout")][nullable[Orientation]] $Orientation) if ($Orientation -ne $null) {$WordDocument.PageLayout.Orientation = $Orientation} } function Set-WordPageSettings { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [nullable[single]] $MarginLeft, [nullable[single]] $MarginRight, [nullable[single]] $MarginTop, [nullable[single]] $MarginBottom, [nullable[single]] $PageWidth, [nullable[single]] $PageHeight, [alias ("PageLayout")][nullable[Orientation]] $Orientation) Set-WordMargins -WordDocument $WordDocument -MarginLeft $MarginLeft -MarginRight $MarginRight -MarginTop $MarginTop -MarginBottom $Mar Set-WordPageSize -WordDocument $WordDocument -PageWidth $PageWidth -PageHeight $PageHeight Set-WordOrientation -WordDocument $WordDocument -Orientation $Orientation } Function Set-WordParagraph { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [Alignment] $Alignment, [Direction] $Direction, [string] $Language, [bool] $Supress = $false) if ($Paragraph -ne $null) { if ($Alignment -ne $null) { Write-Verbose "Set-WordParagraph - Setting Alignment to $Alignment" $Paragraph.Alignment = $Alignment } if ($Direction -ne $null) { Write-Verbose "Set-WordParagraph - Setting Direction to $Direction" $Paragraph.Direction = $Direction } if ($Language -ne $null) { $Culture = [System.Globalization.CultureInfo]::GetCultureInfo($Language) $Paragraph = $Paragraph.Culture($Culture) } } if ($Supress) {return} else {return $Paragraph} } function Set-WordPicture { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [Xceed.Words.NET.DocXElement] $Picture, [string] $ImagePath, [int] $Rotation, [switch] $FlipHorizontal, [switch] $FlipVertical, [int] $ImageWidth, [int] $ImageHeight, [string] $Description, [int] $PictureID, [bool] $Supress = $false) $Paragraph = Remove-WordPicture -WordDocument $WordDocument -Paragraph $Paragraph -PictureID $PictureID -Supress $Supress $data = Add-WordPicture -WordDocument $WordDocument -Paragraph $Paragraph -Picture $Picture -ImagePath $ImagePath -ImageWidth $ImageWidth -ImageHeight $ImageHeight -Rotation $Rotation -FlipHorizontal:$FlipHorizontal -FlipVertical:$FlipVertical -Supress $Supress if ($Supress) {return} else {return $data} } function Set-WordTable { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Table, [nullable[TableBorderType]] $TableBorderType, $Border, [nullable[AutoFit]] $AutoFit, [nullable[TableDesign]] $Design, [nullable[Direction]] $Direction, [switch] $BreakPageAfterTable, [switch] $BreakPageBeforeTable, [nullable[bool]] $BreakAcrossPages, [bool] $Supress) if ($Table -ne $null) { $Table = $table | Set-WordTableDesign -Design $Design $Table = $table | Set-WordTableDirection -Direction $Direction $Table = $table | Set-WordTableBorder -TableBorderType $TableBorderType -Border $Border $Table = $table | Set-WordTablePageBreak -AfterTable:$BreakPageAfterTable -BeforeTable:$BreakPageBeforeTable -BreakAcrossPages $BreakAcrossPages $Table = $table | Set-WordTableAutoFit -AutoFit $AutoFit } if ($Supress) {return} Else {return $Table} } function Set-WordTableAutoFit { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Table, [nullable[AutoFit]] $AutoFit) if ($Table -ne $null -and $AutoFit -ne $null) { Write-Verbose "Set-WordTabelAutofit - Setting Table Autofit to: $AutoFit" $Table.AutoFit = $AutoFit } return $Table } function Set-WordTableBorder { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Table, [nullable[TableBorderType]] $TableBorderType, $Border, [bool] $Supress) if ($null -ne $Table -and $null -ne $TableBorderType -and $null -ne $Border) {$Table.SetBorder($TableBorderType, $Border)} if ($Supress) {return} else {$Table} } function Set-WordTableColumnWidth { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Table, [float[]] $Width = @(), [nullable[float]] $TotalWidth = $null, [bool] $Percentage, [bool] $Supress) if ($Table -ne $null -and $Width -ne $null) { if ($Percentage) { Write-Verbose "Set-WordTableColumnWidth - Option A - Width: $([string] $Width) - Percentage: $Percentage - TotalWidth: $TotalWidth " $Table.SetWidthsPercentage($Width, $TotalWidth) } else { Write-Verbose "Set-WordTableColumnWidth - Option B - Width: $([string] $Width) - Percentage: $Percentage - TotalWidth: $TotalWidth " $Table.SetWidths($Width) } } if ($Supress) {return} else {return $Table} } function Set-WordTableColumnWidthByIndex { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Table, [nullable[int]] $Index, [nullable[double]] $Width) if ($Table -ne $null -and $Index -ne $null -and $Width -ne $null) {$Table.SetColumnWidth($Index, $Width)} } function Set-WordTableDesign { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Table, [nullable[TableDesign]] $Design) if ($Table -ne $null -and $Design -ne $null) {$Table.Design = $Design} return $Table } function Set-WordTableDirection { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Table, [nullable[Direction]] $Direction) if ($Table -ne $null -and $Direction -ne $null) {$Table.SetDirection($Direction)} return $Table } function Set-WordTablePageBreak { [CmdletBinding()] param ([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Table, [switch] $AfterTable, [switch] $BeforeTable, [nullable[bool]] $BreakAcrossPages) if ($Table -ne $null) { if ($BeforeTable) {$Table.InsertPageBreakBeforeSelf()} if ($AfterTable) {$Table.InsertPageBreakAfterSelf()} if ($BreakAcrossPages -ne $null) {$Table.BreakAcrossPages = $BreakAcrossPages} } return $Table } function Set-WordText { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter[]] $Paragraph, [AllowNull()][string[]] $Text = @(), [alias ("C")] [System.Drawing.Color[]]$Color = @(), [alias ("S")] [double[]] $FontSize = @(), [alias ("FontName")] [string[]] $FontFamily = @(), [alias ("B")] [nullable[bool][]] $Bold = @(), [alias ("I")] [nullable[bool][]] $Italic = @(), [alias ("U")] [UnderlineStyle[]] $UnderlineStyle = @(), [alias ('UC')] [System.Drawing.Color[]]$UnderlineColor = @(), [alias ("SA")] [double[]] $SpacingAfter = @(), [alias ("SB")] [double[]] $SpacingBefore = @(), [alias ("SP")] [double[]] $Spacing = @(), [alias ("H")] [highlight[]] $Highlight = @(), [alias ("CA")] [CapsStyle[]] $CapsStyle = @(), [alias ("ST")] [StrikeThrough[]] $StrikeThrough = @(), [alias ("HT")] [HeadingType[]] $HeadingType = @(), [int[]] $PercentageScale = @(), [Misc[]] $Misc = @(), [string[]] $Language = @(), [int[]]$Kerning = @(), [nullable[bool][]] $Hidden = @(), [int[]]$Position = @(), [nullable[bool][]] $NewLine = @(), [switch] $KeepLinesTogether, [switch] $KeepWithNextParagraph, [single[]] $IndentationFirstLine = @(), [single[]] $IndentationHanging = @(), [nullable[Alignment][]] $Alignment = @(), [Direction[]] $Direction = @(), [ShadingType[]] $ShadingType = @(), [System.Drawing.Color[]]$ShadingColor = @(), [Script[]] $Script = @(), [alias ("AppendText")][Switch] $Append, [bool] $Supress = $false) if ($Alignment -eq $null) {$Alignment = @()} Write-Verbose "Set-WordText - Paragraph Count: $($Paragraph.Count)" for ($i = 0; $i -lt $Paragraph.Count; $i++) { Write-Verbose "Set-WordText - Loop: $($i)" Write-Verbose "Set-WordText - $($Paragraph[$i])" Write-Verbose "Set-WordText - $($Paragraph[$i].Text)" if ($null -eq $Paragraph[$i]) {Write-Verbose 'Set-WordText - Paragraph is null'} else {Write-Verbose 'Set-WordText - Paragraph is not null'} if ($null -eq $Color[$i]) {Write-Verbose 'Set-WordText - Color is null'} else {Write-Verbose 'Set-WordText - Color is not null'} $Paragraph[$i] = $Paragraph[$i] | Set-WordTextText -Text $Text[$i] -Append:$Append -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextColor -Color $Color[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextFontSize -FontSize $FontSize[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextFontFamily -FontFamily $FontFamily[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextBold -Bold $Bold[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextItalic -Italic $Italic[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextUnderlineColor -UnderlineColor $UnderlineColor[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextUnderlineStyle -UnderlineStyle $UnderlineStyle[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextSpacingAfter -SpacingAfter $SpacingAfter[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextSpacingBefore -SpacingBefore $SpacingBefore[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextSpacing -Spacing $Spacing[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextHighlight -Highlight $Highlight[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextCapsStyle -CapsStyle $CapsStyle[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextStrikeThrough -StrikeThrough $StrikeThrough[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextPercentageScale -PercentageScale $PercentageScale[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextSpacing -Spacing $Spacing[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextLanguage -Language $Language[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextKerning -Kerning $Kerning[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextMisc -Misc $Misc[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextPosition -Position $Position[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextHidden -Hidden $Hidden[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextShadingType -ShadingColor $ShadingColor[$i] -ShadingType $ShadingType[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextScript -Script $Script[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextHeadingType -HeadingType $HeadingType[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextIndentationFirstLine -IndentationFirstLine $IndentationFirstLine[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextIndentationHanging -IndentationHanging $IndentationHanging[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextAlignment -Alignment $Alignment[$i] -Supress $false $Paragraph[$i] = $Paragraph[$i] | Set-WordTextDirection -Direction $Direction[$i] -Supress $false } } function Set-WordTextText { [CmdletBinding()] param([parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [alias ("S")][AllowNull()] $Text, [switch]$Append, [bool] $Supress = $false) if ($Paragraph -ne $null) { if ($Text -ne $null) { if ($Text -isnot [String]) {throw 'Invalid argument for parameter -Text.'} if ($Append -ne $true) {$Paragraph = Remove-WordText -Paragraph $Paragraph} Write-Verbose "Set-WordTextText - Appending Value $Text" $Paragraph = $Paragraph.Append($Text) } } if ($Supress) {return} else {return $Paragraph} } Add-Type -TypeDefinition @" public enum ShadingType { Text, Paragraph, } "@ Add-Type -TypeDefinition @" public enum StarAndBannerShapes { irregularSeal1, irregularSeal2, star4, star5, star6, star7, star8, star10, star12, star16, star24, star32, ribbon, ribbon2, ellipseRibbon, ellipseRibbon2, verticalScroll, horizontalScroll, wave, doubleWave } "@ Add-Type -TypeDefinition @" public enum StrikeThrough { none, strike, doubleStrike } "@ Add-Type -TypeDefinition @" public enum TableCellBorderType { Top, Bottom, Left, Right, InsideH, InsideV, TopLeftToBottomRight, TopRightToBottomLeft } "@ Add-Type -TypeDefinition @" public enum TableBorderType { Top, Bottom, Left, Right, InsideH, InsideV } "@ Add-Type -TypeDefinition @" public enum TableCellMarginType { left, right, bottom, top } "@ Add-Type -TypeDefinition @" /// <summary> /// Designs\Styles that can be applied to a table. /// </summary> public enum TableDesign { Custom, TableNormal, TableGrid, LightShading, LightShadingAccent1, LightShadingAccent2, LightShadingAccent3, LightShadingAccent4, LightShadingAccent5, LightShadingAccent6, LightList, LightListAccent1, LightListAccent2, LightListAccent3, LightListAccent4, LightListAccent5, LightListAccent6, LightGrid, LightGridAccent1, LightGridAccent2, LightGridAccent3, LightGridAccent4, LightGridAccent5, LightGridAccent6, MediumShading1, MediumShading1Accent1, MediumShading1Accent2, MediumShading1Accent3, MediumShading1Accent4, MediumShading1Accent5, MediumShading1Accent6, MediumShading2, MediumShading2Accent1, MediumShading2Accent2, MediumShading2Accent3, MediumShading2Accent4, MediumShading2Accent5, MediumShading2Accent6, MediumList1, MediumList1Accent1, MediumList1Accent2, MediumList1Accent3, MediumList1Accent4, MediumList1Accent5, MediumList1Accent6, MediumList2, MediumList2Accent1, MediumList2Accent2, MediumList2Accent3, MediumList2Accent4, MediumList2Accent5, MediumList2Accent6, MediumGrid1, MediumGrid1Accent1, MediumGrid1Accent2, MediumGrid1Accent3, MediumGrid1Accent4, MediumGrid1Accent5, MediumGrid1Accent6, MediumGrid2, MediumGrid2Accent1, MediumGrid2Accent2, MediumGrid2Accent3, MediumGrid2Accent4, MediumGrid2Accent5, MediumGrid2Accent6, MediumGrid3, MediumGrid3Accent1, MediumGrid3Accent2, MediumGrid3Accent3, MediumGrid3Accent4, MediumGrid3Accent5, MediumGrid3Accent6, DarkList, DarkListAccent1, DarkListAccent2, DarkListAccent3, DarkListAccent4, DarkListAccent5, DarkListAccent6, ColorfulShading, ColorfulShadingAccent1, ColorfulShadingAccent2, ColorfulShadingAccent3, ColorfulShadingAccent4, ColorfulShadingAccent5, ColorfulShadingAccent6, ColorfulList, ColorfulListAccent1, ColorfulListAccent2, ColorfulListAccent3, ColorfulListAccent4, ColorfulListAccent5, ColorfulListAccent6, ColorfulGrid, ColorfulGridAccent1, ColorfulGridAccent2, ColorfulGridAccent3, ColorfulGridAccent4, ColorfulGridAccent5, ColorfulGridAccent6, None }; "@ Add-Type -TypeDefinition @" public enum TableOfContentsSwitches { None = 0 << 0, A = 1 << 0, B = 1 << 1, C = 1 << 2, D = 1 << 3, F = 1 << 4, H = 1 << 5, L = 1 << 6, N = 1 << 7, O = 1 << 8, P = 1 << 9, S = 1 << 10, T = 1 << 11, U = 1 << 12, W = 1 << 13, X = 1 << 14, Z = 1 << 15 } "@ Add-Type -TypeDefinition @" public enum TabStopPositionLeader { none, dot, underscore, hyphen } "@ Add-Type -TypeDefinition @" public enum TextDirection { btLr, right, } "@ Add-Type -TypeDefinition @" public enum UnderlineStyle { none = 0, singleLine = 1, words = 2, doubleLine = 3, dotted = 4, thick = 6, dash = 7, dotDash = 9, dotDotDash = 10, wave = 11, dottedHeavy = 20, dashedHeavy = 23, dashDotHeavy = 25, dashDotDotHeavy = 26, dashLongHeavy = 27, dashLong = 39, wavyDouble = 43, wavyHeavy = 55 } "@ Add-Type -TypeDefinition @" public enum VerticalAlignment { Top, Center, Bottom } "@ Add-Type -Path $PSScriptRoot\Lib\Default\Xceed.Words.NET.dll Export-ModuleMember -Function @('Add-WordBarChart', 'Add-WordChartSeries', 'Add-WordCustomProperty', 'Add-WordEquation', 'Add-WordFooter', 'Add-WordHeader', 'Add-WordHyperLink', 'Add-WordLine', 'Add-WordLineChart', 'Add-WordList', 'Add-WordListItem', 'Add-WordPageBreak', 'Add-WordPageCount', 'Add-WordParagraph', 'Add-WordPicture', 'Add-WordPieChart', 'Add-WordProtection', 'Add-WordSection', 'Add-WordTable', 'Add-WordTableCellValue', 'Add-WordTableColumn', 'Add-WordTableRow', 'Add-WordTableTitle', 'Add-WordTabStopPosition', 'Add-WordText', 'Add-WordTOC', 'Add-WordTocItem', 'Convert-ListToHeadings', 'Copy-WordTableRow', 'Format-WordListItem', 'Get-ColorFromARGB', 'Get-WordCustomProperty', 'Get-WordDocument', 'Get-WordFooter', 'Get-WordHeader', 'Get-WordListItemParagraph', 'Get-WordPageSettings', 'Get-WordParagraphForList', 'Get-WordParagraphs', 'Get-WordPicture', 'Get-WordSection', 'Get-WordTable', 'Get-WordTableRow', 'Merge-WordDocument', 'New-WordBlock', 'New-WordBlockList', 'New-WordBlockPageBreak', 'New-WordBlockParagraph', 'New-WordBlockTable', 'New-WordDocument', 'New-WordListItem', 'New-WordTable', 'New-WordTableBorder', 'Remove-WordParagraph', 'Remove-WordPicture', 'Remove-WordTable', 'Remove-WordTableColumn', 'Remove-WordTableRow', 'Remove-WordText', 'Save-WordDocument', 'Set-WordHyperLink', 'Set-WordList', 'Set-WordMargins', 'Set-WordOrientation', 'Set-WordPageSettings', 'Set-WordPageSize', 'Set-WordParagraph', 'Set-WordPicture', 'Set-WordTable', 'Set-WordTableCell', 'Set-WordTableCellFillColor', 'Set-WordTableCellShadingColor', 'Set-WordTableColumnWidth', 'Set-WordTableColumnWidthByIndex', 'Set-WordTableRowMergeCells', 'Set-WordText', 'Set-WordTextAlignment', 'Set-WordTextBold', 'Set-WordTextCapsStyle', 'Set-WordTextColor', 'Set-WordTextDirection', 'Set-WordTextFontFamily', 'Set-WordTextFontSize', 'Set-WordTextHeadingType', 'Set-WordTextHidden', 'Set-WordTextHighlight', 'Set-WordTextIndentationFirstLine', 'Set-WordTextIndentationHanging', 'Set-WordTextItalic', 'Set-WordTextKerning', 'Set-WordTextLanguage', 'Set-WordTextMisc', 'Set-WordTextPercentageScale', 'Set-WordTextPosition', 'Set-WordTextScript', 'Set-WordTextShadingType', 'Set-WordTextSpacing', 'Set-WordTextSpacingAfter', 'Set-WordTextSpacingBefore', 'Set-WordTextStrikeThrough', 'Set-WordTextUnderlineColor', 'Set-WordTextUnderlineStyle') -Alias @('Add-WordPageNumber') |