Public/PSWordParagraph.ps1
# Paragraph InsertParagraph() # Paragraph InsertParagraph( int index, string text, bool trackChanges ) # Paragraph InsertParagraph( Paragraph p ) # Paragraph InsertParagraph( int index, Paragraph p ) # Paragraph InsertParagraph( int index, string text, bool trackChanges, Formatting formatting ) # Paragraph InsertParagraph( string text ) # Paragraph InsertParagraph( string text, bool trackChanges ) # Paragraph InsertParagraph( string text, bool trackChanges, Formatting formatting ) function Add-WordText { [CmdletBinding()] param ( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.Container]$WordDocument, [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [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 = @(), # "Value must be one of the following: 200, 150, 100, 90, 80, 66, 50 or 33" [Misc[]] $Misc = @(), [string[]] $Language = @(), [int[]]$Kerning = @(), # "Value must be one of the following: 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48 or 72" [nullable[bool][]]$Hidden = @(), [int[]]$Position = @(), # "Value must be in the range -1585 - 1585" [nullable[bool][]]$NewLine = @(), [switch] $KeepLinesTogether, # not done [switch] $KeepWithNextParagraph, # not done [single[]] $IndentationFirstLine = @(), [single[]] $IndentationHanging = @(), [Alignment[]] $Alignment = @(), [Direction[]] $Direction = @(), [ShadingType[]] $ShadingType = @(), [Script[]] $Script = @(), [bool] $Supress = $true ) if ($Text.Count -eq 0) { return } if ($Paragraph -ne $null) { $Paragraph = $Paragraph.InsertParagraphAfterSelf($Paragraph) } 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() } else { $Paragraph = $WordDocument.InsertParagraph() } } $Paragraph = $Paragraph.Append($Text[$i]) } else { $Paragraph = $Paragraph.Append($Text[$i]) } $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 -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 Set-WordText { [CmdletBinding()] param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter[]] $Paragraph, [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 = @(), # "Value must be one of the following: 200, 150, 100, 90, 80, 66, 50 or 33" [Misc[]] $Misc = @(), [string[]] $Language = @(), [int[]]$Kerning = @(), # "Value must be one of the following: 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48 or 72" [nullable[bool][]] $Hidden = @(), [int[]]$Position = @(), # "Value must be in the range -1585 - 1585" [nullable[bool][]] $NewLine = @(), [switch] $KeepLinesTogether, [switch] $KeepWithNextParagraph, [single[]] $IndentationFirstLine = @(), [single[]] $IndentationHanging = @(), [Alignment[]] $Alignment = @(), [Direction[]] $Direction = @(), [ShadingType[]] $ShadingType = @(), [Script[]] $Script = @(), [bool] $Supress = $true ) 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-Color 'Paragraph is null' } else { Write-Color 'Paragraph is not null' } if ($null -eq $Color[$i]) { Write-Color 'Color is null' } else { Write-Color 'Color is not null' } $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 -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-WordTextFontSize { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [alias ("S")] [nullable[double]] $FontSize, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $FontSize -ne $null) { $Paragraph = $Paragraph.FontSize($FontSize) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextColor { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [alias ("C")] [nullable[System.Drawing.Color]] $Color, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Color -ne $null) { $Paragraph = $Paragraph.Color($Color) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextBold { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[bool]] $Bold, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Bold -ne $null -and $Bold -eq $true) { $Paragraph = $Paragraph.Bold() } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextItalic { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[bool]] $Italic, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Italic -ne $null -and $Italic -eq $true) { $Paragraph = $Paragraph.Italic() } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextFontFamily { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [string] $FontFamily, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $FontFamily -ne $null -and $FontFamily -ne '') { $Paragraph = $Paragraph.Font($FontFamily) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextUnderlineStyle { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[UnderlineStyle]] $UnderlineStyle, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $UnderlineStyle -ne $null) { $Paragraph = $Paragraph.UnderlineStyle($UnderlineStyle) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextUnderlineColor { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[System.Drawing.Color]] $UnderlineColor, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $UnderlineColor -ne $null) { $Paragraph = $Paragraph.UnderlineColor($UnderlineColor) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextSpacingAfter { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[double]] $SpacingAfter, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $SpacingAfter -ne $null) { $Paragraph = $Paragraph.SpacingAfter($SpacingAfter) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextSpacingBefore { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[double]] $SpacingBefore, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $SpacingBefore -ne $null) { $Paragraph = $Paragraph.SpacingBefore($SpacingBefore) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextSpacing { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[double]] $Spacing, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Spacing -ne $null) { $Paragraph = $Paragraph.Spacing($Spacing) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextHighlight { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[Highlight]] $Highlight, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Highlight -ne $null) { $Paragraph = $Paragraph.Highlight($Highlight) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextCapsStyle { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[CapsStyle]] $CapsStyle, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $CapsStyle -ne $null) { $Paragraph = $Paragraph.CapsStyle($CapsStyle) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextStrikeThrough { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[StrikeThrough]] $StrikeThrough, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $StrikeThrough -ne $null) { $Paragraph = $Paragraph.StrikeThrough($StrikeThrough) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextShadingType { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[ShadingType]] $ShadingType, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $ShadingType -ne $null) { $Paragraph = $Paragraph.ShadingType($ShadingType) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextPercentageScale { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[int]]$PercentageScale, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $PercentageScale -ne $null) { $Paragraph = $Paragraph.PercentageScale($PercentageScale) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextLanguage { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [string]$Language, [bool] $Supress = $true ) 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 { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[int]] $Kerning, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Kerning -ne $null) { $Paragraph = $Paragraph.Kerning($Kerning) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextMisc { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[Misc]] $Misc, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Misc -ne $null) { $Paragraph = $Paragraph.Misc($Misc) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextPosition { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[int]]$Position, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Position -ne $null) { $Paragraph = $Paragraph.Position($Position) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextHidden { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[bool]] $Hidden, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Hidden -ne $null) { $Paragraph = $Paragraph.Hidden($Hidden) } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextHeadingType { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[HeadingType]] $HeadingType, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $HeadingType -ne $null) { $Paragraph.StyleName = $HeadingType } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextIndentationFirstLine { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[single]] $IndentationFirstLine, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $IndentationFirstLine -ne $null) { $Paragraph.IndentationFirstLine = $IndentationFirstLine } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextAlignment { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[Alignment]] $Alignment, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Alignment -ne $null) { $Paragraph.Alignment = $Alignment } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextIndentationHanging { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[single]] $IndentationHanging, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $IndentationHanging -ne $null) { $Paragraph.IndentationHanging = $IndentationHanging } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextDirection { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[Direction]] $Direction, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Direction -ne $null) { $Paragraph.Direction = $Direction } if ($Supress) { return } else { return $Paragraph } } function Set-WordTextScript { param( [parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Words.NET.InsertBeforeOrAfter] $Paragraph, [nullable[Script]] $Script, [bool] $Supress = $true ) if ($Paragraph -ne $null -and $Script -ne $null) { $Paragraph = $Paragraph.Script($Script) } if ($Supress) { return } else { return $Paragraph } } |