Documentimo.psm1
function Documentimo { [alias('Doc', 'New-Documentimo')] param([Parameter(Position = 0)][ValidateNotNull()][ScriptBlock] $Content = $(Throw "Documentimo requires opening and closing brace."), [string] $FilePath, [switch] $Open) $WordDocument = New-WordDocument -FilePath $FilePath $Script:Parameters.WordDocument = $WordDocument Invoke-Command -ScriptBlock $Content Save-WordDocument -WordDocument $WordDocument -Supress $true -Language 'en-US' -Verbose -OpenDocument:$Open } function DocumentimoChart { [alias('DocChart', 'New-DocumentimoChart')] param([Array] $DataTable, [string] $Title, [string] $Key, [string] $Value, [ChartLegendPosition] $LegendPosition = [ChartLegendPosition]::Bottom, [bool] $LegendOverlay) if ($DataTable.Count -gt 0) { if ($DataTable[0] -is [System.Collections.IDictionary]) { $TemporaryNames = $DataTable.Keys $Names = foreach ($Name in $TemporaryNames) {"$Name ($($DataTable.$Name))"} $Values = $DataTable.Values } else { if (($Key -ne '') -and ($Value -ne '')) { $Names = for ($i = 0; $i -lt $DataTable.Count; $i++) {"$($DataTable[$i].$Key) ($($DataTable[$i].$Value))"} $Values = $DataTable.$Value } else {return} } if (($Values.Count -eq $Names.Count) -and ($Values.Count -gt 0)) { Add-WordParagraph -WordDocument $Script:Parameters.WordDocument -Supress $True Add-WordPieChart -WordDocument $Script:Parameters.WordDocument -ChartName $Title -Names $Names -Values $Values -ChartLegendPosition $LegendPosition -ChartLegendOverlay $LegendOverlay } else {Write-Warning "DocumentimoChart - Names and Values count doesn't match or equals 0"} } } function DocumentimoNumbering { [alias('DocNumbering', 'New-DocumentimoNumbering')] param([Parameter(Position = 0)][ScriptBlock] $Content, [string] $Text, [int] $Level = 0, [ListItemType] $ItemType = [ListItemType]::Numbered, [HeadingType] $HeadingType = [HeadingType]::Heading1) $TOC = Add-WordTocItem -WordDocument $Script:Parameters.WordDocument -Text $Text -ListLevel $Level -ListItemType $ItemType -HeadingType $HeadingType if ($Content) {Invoke-Command -ScriptBlock $Content} } function DocumentimoPageBreak { [alias('New-DocumentimoPageBreak', 'DocPageBreak')] param([int] $Count = 1) $i = 0 While ($i -lt $Count) { Write-Verbose "New-WordBlockPageBreak - PageBreak $i" Add-WordPageBreak -Supress $True -WordDocument $Script:Parameters.WordDocument $i++ } } function DocumentimoTable { [alias('New-DocumentimoTable', 'DocTable')] param([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, [string] $OverwriteTitle) if ($OverWriteTitle) { [Alignment] $TitleAlignment = [Alignment]::center [System.Drawing.Color] $TitleColor = [System.Drawing.Color]::Black $Table = Add-WordTable -WordDocument $Script:Parameters.WordDocument -Supress $false -DataTable $DataTable -Design $Design -AutoFit $AutoFit $Table = Set-WordTableRowMergeCells -Table $Table -RowNr 0 -MergeAll $TableParagraph = Get-WordTableRow -Table $Table -RowNr 0 -ColumnNr 0 $TableParagraph = Set-WordText -Paragraph $TableParagraph -Text $OverwriteTitle -Alignment $TitleAlignment -Color $TitleColor } else {$Table = Add-WordTable -WordDocument $Script:Parameters.WordDocument -Supress $true -DataTable $DataTable -Design $Design -AutoFit $AutoFit} } function DocumentimoText { [alias('New-DocumentimoText', 'DocText')] param([Parameter(Mandatory = $false, Position = 0)][ScriptBlock] $TextBlock, [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, [switch] $LineBreak) if ($TextBlock) {$Text = (Invoke-Command -ScriptBlock $TextBlock)} Add-WordText -WordDocument $Script:Parameters.WordDocument -Text $Text -Color $Color -Supress $true if ($LineBreak) {Add-WordParagraph -WordDocument $Script:Parameters.WordDocument -Supress $True} } function DocumentimoTableOfContents { [alias('New-DocumentimoTOC', 'DocToc', 'DocumentimoTOC', 'DocTableOfContents')] param([string] $Title, [int] $RightTabPos, [TableOfContentsSwitches[]] $Switches) Add-WordToc -WordDocument $Script:Parameters.WordDocument -Title $Title -Switches $Switches -RightTabPos $RightTabPos -Supress $True } $Script:Parameters = @{WordDocument = $null} Export-ModuleMember -Function @('Documentimo', 'DocumentimoChart', 'DocumentimoNumbering', 'DocumentimoPageBreak', 'DocumentimoTable', 'DocumentimoTableOfContents', 'DocumentimoText') -Alias @('Doc', 'DocChart', 'DocNumbering', 'DocPageBreak', 'DocTable', 'DocTableOfContents', 'DocText', 'DocToc', 'DocumentimoTOC', 'New-Documentimo', 'New-DocumentimoChart', 'New-DocumentimoNumbering', 'New-DocumentimoPageBreak', 'New-DocumentimoTable', 'New-DocumentimoText', 'New-DocumentimoTOC') |