Documentimo.psm1
function Documentimo { [CmdletBinding()] [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 if ($null -ne $Content) { $Array = Invoke-Command -ScriptBlock $Content New-WordProcessing -Content $Array -WordDocument $WordDocument } Save-WordDocument -WordDocument $WordDocument -Supress $true -Language 'en-US' -Verbose -OpenDocument:$Open } function DocChart { [CmdletBinding()] [alias('DocumentimoChart', 'New-DocumentimoChart')] param([Array] $DataTable, [string] $Title, [string] $Key, [string] $Value, [Xceed.Words.NET.ChartLegendPosition] $LegendPosition = [Xceed.Words.NET.ChartLegendPosition]::Bottom, [bool] $LegendOverlay) [PSCustomObject] @{ObjectType = 'ChartPie' DataTable = $DataTable Title = $Title Key = $Key Value = $Value LegendPosition = $LegendPosition LegendOverlay = $LegendOverlay } } function DocList { [CmdletBinding()] [alias('DocumentimoList', 'New-DocumentimoList')] param([ScriptBlock] $ListItems, [alias('ListType')][Xceed.Words.NET.ListItemType] $Type = [Xceed.Words.NET.ListItemType]::Bulleted) [PSCustomObject] @{ObjectType = 'List' ListItems = Invoke-Command -ScriptBlock $ListItems Type = $Type } } function DocListItem { [CmdletBinding()] [alias('DocumentimoListItem', 'New-DocumentimoListItem')] param([ValidateRange(0, 8)] [int] $Level, [string] $Text, [nullable[int]] $StartNumber, [bool]$TrackChanges = $false, [bool]$ContinueNumbering = $false, [bool]$Supress = $false) [PSCustomObject] @{ObjectType = 'ListItem' Level = $Level Text = $Text StartNumber = $StartNumber TrackChanges = $TrackChanges ContinueNumbering = $ContinueNumbering } } function DocNumbering { [CmdletBinding()] [alias('DocumentimoNumbering', 'New-DocumentimoNumbering')] param([Parameter(Position = 0)][ScriptBlock] $Content, [string] $Text, [int] $Level = 0, [Xceed.Words.NET.ListItemType] $Type = [Xceed.Words.NET.ListItemType]::Numbered, [Xceed.Words.NET.HeadingType] $Heading = [Xceed.Words.NET.HeadingType]::Heading1) [PSCustomObject] @{ObjectType = 'TocItem' Text = $Text Content = $Content Level = $Level Type = $Type Heading = $Heading } } function DocPageBreak { [CmdletBinding()] [alias('DocumentimoPageBreak', 'New-DocumentimoPageBreak')] param([int] $Count = 1) [PSCustomObject] @{ObjectType = 'PageBreak' Count = $Count } } function DocTable { [CmdletBinding()] [alias('DocumentimoTable', 'New-DocumentimoTable')] param([Array] $DataTable, [Xceed.Words.NET.AutoFit] $AutoFit = [Xceed.Words.NET.AutoFit]::Window, [Xceed.Words.NET.TableDesign] $Design, [Xceed.Words.NET.Direction] $Direction = [Xceed.Words.NET.Direction]::LeftToRight, [int] $MaximumColumns = 5, [string] $OverwriteTitle, [Xceed.Words.NET.Alignment] $OverwriteTitleAlignment = [Xceed.Words.NET.Alignment]::center, [System.Drawing.Color] $OverwriteTitleColor = [System.Drawing.Color]::Black) [PSCustomObject] @{ObjectType = 'Table' DataTable = $DataTable AutoFit = $AutoFit Design = $Design Direction = $Direction MaximumColumns = $MaximumColumns OverwriteTitle = $OverwriteTitle OverwriteTitleAlignment = $OverwriteTitleAlignment OverwriteTitleColor = $OverwriteTitleColor } } function DocText { [CmdletBinding()] [alias('DocumentimoText', 'New-DocumentimoText')] param([Parameter(Mandatory = $false, Position = 0)][ScriptBlock] $TextBlock, [String[]]$Text, [System.Drawing.Color[]]$Color = @(), [switch] $LineBreak) if ($TextBlock) {$Text = (Invoke-Command -ScriptBlock $TextBlock)} [PSCustomObject] @{ObjectType = 'Text' Text = $Text Color = $Color LineBreak = $LineBreak } } function DocToc { [CmdletBinding()] [alias('DocumentimoTOC', 'New-DocumentimoTOC')] param([string] $Title, [int] $RightTabPos, [Xceed.Words.Net.TableOfContentsSwitches] $Switches) [PSCustomObject] @{ObjectType = 'TOC' Title = $Title RightTabPos = $RightTabPos Switches = $Switches } } function New-DocWordChart { [CmdletBinding()] param([Xceed.Words.NET.Container] $WordDocument, [PSCustomObject] $Parameters) [Array] $DataTable = $Parameters.DataTable [string] $Key = $Parameters.Key [string] $Value = $Parameters.Value [Xceed.Words.NET.ChartLegendPosition] $LegendPosition = $Parameters.LegendPosition [bool] $LegendOverlay = $Parameters.LegendOverlay [string] $Title = $Parameters.Title 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 $WordDocument -Supress $True Add-WordPieChart -WordDocument $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 New-DocWordList { [CmdletBinding()] param([Xceed.Words.NET.Container] $WordDocument, [PSCustomObject] $Parameters) $List = $null foreach ($Item in $Parameters.ListItems) { if ($null -eq $List) { $List = $WordDocument.AddList($Item.Text, $Item.Level, $Parameters.Type, $Item.StartNumber, $Item.TrackChanges, $Item.ContinueNumbering) $Paragraph = $List.Items[$List.Items.Count - 1] } else { $List = $WordDocument.AddListItem($List, $Item.Text, $Item.Level, $Parameters.Type, $Item.StartNumber, $Item.TrackChanges, $Item.ContinueNumbering) $Paragraph = $List.Items[$List.Items.Count - 1] } } $null = Add-WordListItem -WordDocument $WordDocument -List $List } function New-DocWordNumbering { [CmdletBinding()] param([Xceed.Words.NET.Container] $WordDocument, [PSCustomObject] $Parameters) $TOC = Add-WordTocItem -WordDocument $WordDocument -Text $Parameters.Text -ListLevel $Parameters.Level -ListItemType $Parameters.Type -HeadingType $Parameters.Heading if ($Parameters.Content) { $Content = Invoke-Command -ScriptBlock $Parameters.Content New-WordProcessing -Content $Content -WordDocument $WordDocument } } function New-DocWordPageBreak { [CmdletBinding()] param([Xceed.Words.NET.Container] $WordDocument, [PSCustomObject] $Parameters) $i = 0 While ($i -lt $Parameters.Count) { Write-Verbose "New-WordBlockPageBreak - PageBreak $i" Add-WordPageBreak -Supress $True -WordDocument $WordDocument $i++ } } function New-DocWordTable { [CmdletBinding()] param([Xceed.Words.NET.Container] $WordDocument, [PSCustomObject] $Parameters) if ($Parameters.OverWriteTitle) { [Xceed.Words.NET.Alignment] $TitleAlignment = $Parameters.OverwriteTitleAlignment [System.Drawing.Color] $TitleColor = $Parameters.OverwriteTitleColor $Table = Add-WordTable -WordDocument $WordDocument -Supress $false -DataTable $Parameters.DataTable -Design $Parameters.Design -AutoFit $Parameters.AutoFit $Table = Set-WordTableRowMergeCells -Table $Table -RowNr 0 -MergeAll $TableParagraph = Get-WordTableRow -Table $Table -RowNr 0 -ColumnNr 0 $TableParagraph = Set-WordText -Paragraph $TableParagraph -Text $Parameters.OverwriteTitle -Alignment $TitleAlignment -Color $TitleColor } else {$Table = Add-WordTable -WordDocument $WordDocument -Supress $true -DataTable $Parameters.DataTable -Design $Parameters.Design -AutoFit $Parameters.AutoFit} } function New-DocWordText { [CmdletBinding()] param([Xceed.Words.NET.Container] $WordDocument, [PSCustomObject] $Parameters) if ($Parameters.Text) {Add-WordText -WordDocument $WordDocument -Text $Parameters.Text -Color $Parameters.Color -Supress $true} if ($Parameters.LineBreak) {Add-WordParagraph -WordDocument $WordDocument -Supress $True} } function New-DocWordTOC { [CmdletBinding()] param([Xceed.Words.NET.Container] $WordDocument, [PSCustomObject] $Parameters) Add-WordToc -WordDocument $WordDocument -Title $Parameters.Title -Switches $Parameters.Switches -RightTabPos $Parameters.RightTabPos -Supress $True } function New-WordProcessing { [CmdletBinding()] param([Array] $Content, [Xceed.Words.NET.Container] $WordDocument) if ($Content.Count -gt 0) {foreach ($Parameters in $Content) {if ($Parameters.ObjectType -eq 'List') {New-DocWordList -WordDocument $WordDocument -Parameters $Parameters} elseif ($Parameters.ObjectType -eq 'Table') {New-DocWordTable -WordDocument $WordDocument -Parameters $Parameters} elseif ($Parameters.ObjectType -eq 'TOC') {New-DocWordTOC -WordDocument $WordDocument -Parameters $Parameters} elseif ($Parameters.ObjectType -eq 'Text') {New-DocWordText -WordDocument $WordDocument -Parameters $Parameters} elseif ($Parameters.ObjectType -eq 'TocItem') {New-DocWordNumbering -WordDocument $WordDocument -Parameters $Parameters} elseif ($Parameters.ObjectType -eq 'PageBreak') {New-DocWordPageBreak -WordDocument $WordDocument -Parameters $Parameters} elseif ($Parameters.ObjectType -eq 'ChartPie') {New-DocWordChart -WordDocument $WordDocument -Parameters $Parameters}}} } Export-ModuleMember -Function @('DocChart', 'DocList', 'DocListItem', 'DocNumbering', 'DocPageBreak', 'DocTable', 'DocText', 'DocToc', 'Documentimo') -Alias @('Doc', 'DocumentimoChart', 'DocumentimoList', 'DocumentimoListItem', 'DocumentimoNumbering', 'DocumentimoPageBreak', 'DocumentimoTable', 'DocumentimoText', 'DocumentimoTOC', 'New-Documentimo', 'New-DocumentimoChart', 'New-DocumentimoList', 'New-DocumentimoListItem', 'New-DocumentimoNumbering', 'New-DocumentimoPageBreak', 'New-DocumentimoTable', 'New-DocumentimoText', 'New-DocumentimoTOC') |