Skip to content
This repository was archived by the owner on Apr 12, 2022. It is now read-only.

Commit b22e2d7

Browse files
committed
Add Set-WordTextStyle
1 parent ff8b677 commit b22e2d7

File tree

5 files changed

+27
-5
lines changed

5 files changed

+27
-5
lines changed

PSWriteWord.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
CompatiblePSEditions = @('Desktop')
77
Copyright = '(c) 2011 - 2022 Przemyslaw Klys @ Evotec. All rights reserved.'
88
Description = 'Simple project to create Microsoft Word in PowerShell without having Office installed.'
9-
FunctionsToExport = @('Get-WordBookmark', 'Set-WordBookmark', 'New-WordBlock', 'New-WordBlockList', 'New-WordBlockPageBreak', 'New-WordBlockParagraph', 'New-WordBlockTable', 'Add-WordBarChart', 'Add-WordChartSeries', 'Add-WordLineChart', 'Add-WordPieChart', 'Documentimo', 'DocChart', 'DocList', 'DocListItem', 'DocNumbering', 'DocPageBreak', 'DocTable', 'DocText', 'DocToc', 'Add-WordFooter', 'Add-WordHeader', 'Get-WordFooter', 'Get-WordHeader', 'Add-WordHyperLink', 'Add-WordList', 'Add-WordListItem', 'Convert-ListToHeadings', 'New-WordList', 'New-WordListItem', 'New-WordListItemInternal', 'Set-WordList', 'Get-WordDocument', 'Merge-WordDocument', 'New-WordDocument', 'Save-WordDocument', 'Add-WordCustomProperty', 'Add-WordEquation', 'Add-WordLine', 'Add-WordPageCount', 'Add-WordProtection', 'Add-WordSection', 'Add-WordTabStopPosition', 'Get-WordCustomProperty', 'Get-WordPageSettings', 'Get-WordSection', 'Set-WordMargins', 'Set-WordOrientation', 'Set-WordPageSettings', 'Set-WordPageSize', 'Add-WordPageBreak', 'Add-WordParagraph', 'Add-WordText', 'Get-WordListItemParagraph', 'Get-WordParagraphs', 'Get-WordParagraphForList', 'Remove-WordParagraph', 'Remove-WordText', 'Set-WordParagraph', '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-WordTextReplace', 'Set-WordTextScript', 'Set-WordTextShadingType', 'Set-WordTextSpacing', 'Set-WordTextSpacingAfter', 'Set-WordTextSpacingBefore', 'Set-WordTextStrikeThrough', 'Set-WordTextUnderlineColor', 'Set-WordTextUnderlineStyle', 'Add-WordPicture', 'Get-WordPicture', 'Remove-WordPicture', 'Set-WordPicture', 'Add-WordTable', 'Add-WordTableCellValue', 'Add-WordTableColumn', 'Add-WordTableRow', 'Add-WordTableTitle', 'Copy-WordTableRow', 'Get-WordTable', 'Get-WordTableRow', 'New-WordTable', 'New-WordTableBorder', 'Remove-WordTable', 'Remove-WordTableColumn', 'Remove-WordTableRow', 'Set-WordTable', 'Set-WordTableAutoFit', 'Set-WordTableBorder', 'Set-WordTableCell', 'Set-WordTableCellFillColor', 'Set-WordTableCellShadingColor', 'Set-WordTableColumnWidth', 'Set-WordTableColumnWidthByIndex', 'Set-WordTableDesign', 'Set-WordTableDirection', 'Set-WordTablePageBreak', 'Set-WordTableRowMergeCells', 'Add-WordTOC', 'Add-WordTocItem')
9+
FunctionsToExport = @('Get-WordBookmark', 'Set-WordBookmark', 'New-WordBlock', 'New-WordBlockList', 'New-WordBlockPageBreak', 'New-WordBlockParagraph', 'New-WordBlockTable', 'Add-WordBarChart', 'Add-WordChartSeries', 'Add-WordLineChart', 'Add-WordPieChart', 'Documentimo', 'DocChart', 'DocList', 'DocListItem', 'DocNumbering', 'DocPageBreak', 'DocTable', 'DocText', 'DocToc', 'Add-WordFooter', 'Add-WordHeader', 'Get-WordFooter', 'Get-WordHeader', 'Add-WordHyperLink', 'Add-WordList', 'Add-WordListItem', 'Convert-ListToHeadings', 'New-WordList', 'New-WordListItem', 'New-WordListItemInternal', 'Set-WordList', 'Get-WordDocument', 'Merge-WordDocument', 'New-WordDocument', 'Save-WordDocument', 'Add-WordCustomProperty', 'Add-WordEquation', 'Add-WordLine', 'Add-WordPageCount', 'Add-WordProtection', 'Add-WordSection', 'Add-WordTabStopPosition', 'Get-WordCustomProperty', 'Get-WordPageSettings', 'Get-WordSection', 'Set-WordMargins', 'Set-WordOrientation', 'Set-WordPageSettings', 'Set-WordPageSize', 'Add-WordPageBreak', 'Add-WordParagraph', 'Add-WordText', 'Get-WordListItemParagraph', 'Get-WordParagraphs', 'Get-WordParagraphForList', 'Remove-WordParagraph', 'Remove-WordText', 'Set-WordParagraph', '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-WordTextReplace', 'Set-WordTextScript', 'Set-WordTextShadingType', 'Set-WordTextSpacing', 'Set-WordTextSpacingAfter', 'Set-WordTextSpacingBefore', 'Set-WordTextStrikeThrough', 'Set-WordTextUnderlineColor', 'Set-WordTextUnderlineStyle', 'Add-WordPicture', 'Get-WordPicture', 'Remove-WordPicture', 'Set-WordPicture', 'Add-WordTable', 'Add-WordTableCellValue', 'Add-WordTableColumn', 'Add-WordTableRow', 'Add-WordTableTitle', 'Copy-WordTableRow', 'Get-WordTable', 'Get-WordTableRow', 'New-WordTable', 'New-WordTableBorder', 'Remove-WordTable', 'Remove-WordTableColumn', 'Remove-WordTableRow', 'Set-WordTable', 'Set-WordTableAutoFit', 'Set-WordTableBorder', 'Set-WordTableCell', 'Set-WordTableCellFillColor', 'Set-WordTableCellShadingColor', 'Set-WordTableColumnWidth', 'Set-WordTableColumnWidthByIndex', 'Set-WordTableDesign', 'Set-WordTableDirection', 'Set-WordTablePageBreak', 'Set-WordTableRowMergeCells', 'Add-WordTOC', 'Add-WordTocItem', 'Set-WordTextStyle')
1010
GUID = '6314c78a-d011-4489-b462-91b05ec6a5c4'
1111
ModuleVersion = '1.1.14'
1212
PowerShellVersion = '5.1'

Private/Set-WordContinueFormatting.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
[alias ("CA")] [Xceed.Document.NET.CapsStyle[]] $CapsStyle = @(),
1616
[alias ("ST")] [Xceed.Document.NET.StrikeThrough[]] $StrikeThrough = @(),
1717
[alias ("HT")] [Xceed.Document.NET.HeadingType[]] $HeadingType = @(),
18+
[string[]] $Style = @(),
1819
[int[]] $PercentageScale = @(), # "Value must be one of the following: 200, 150, 100, 90, 80, 66, 50 or 33"
1920
[Xceed.Document.NET.Misc[]] $Misc = @(),
2021
[string[]] $Language = @(),
@@ -54,6 +55,7 @@
5455
if ($null -eq $DirectionFormatting[$RowNr] -and $null -ne $DirectionFormatting[$RowNr - 1]) { $DirectionFormatting += $DirectionFormatting[$RowNr - 1] }
5556
if ($null -eq $ShadingType[$RowNr] -and $null -ne $ShadingType[$RowNr - 1]) { $ShadingType += $ShadingType[$RowNr - 1] }
5657
if ($null -eq $Script[$RowNr] -and $null -ne $Script[$RowNr - 1]) { $Script += $Script[$RowNr - 1] }
58+
if ($null -eq $Style[$RowNr] -and $null -ne $Style[$RowNr - 1]) { $Style += $Style[$RowNr - 1] }
5759
}
5860
Write-Verbose "Set-WordContinueFormatting - Alignment: $Alignment"
5961
return @(
@@ -82,6 +84,7 @@
8284
$Alignment,
8385
$DirectionFormatting,
8486
$ShadingType,
85-
$Script
87+
$Script,
88+
$Style
8689
)
8790
}

Public/Paragraph/Add-WordText.ps1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
[alias ("CA")] [Xceed.Document.NET.CapsStyle[]] $CapsStyle = @(),
2121
[alias ("ST")] [Xceed.Document.NET.StrikeThrough[]] $StrikeThrough = @(),
2222
[alias ("HT")] [Xceed.Document.NET.HeadingType[]] $HeadingType = @(),
23+
[string[]] $Style = @(),
2324
[int[]] $PercentageScale = @(), # "Value must be one of the following: 200, 150, 100, 90, 80, 66, 50 or 33"
2425
[Xceed.Document.NET.Misc[]] $Misc = @(),
2526
[string[]] $Language = @(),
@@ -119,7 +120,8 @@
119120
-IndentationHanging $IndentationHanging `
120121
-Alignment $Alignment `
121122
-ShadingType $ShadingType `
122-
-Script $Script
123+
-Script $Script `
124+
-Style $Style
123125

124126
$Color = $Formatting[0]
125127
$FontSize = $Formatting[1]
@@ -145,8 +147,9 @@
145147
$IndentationHanging = $Formatting[21]
146148
$Alignment = $Formatting[22]
147149
#$DirectionFormatting = $Formatting[23]
148-
$ShadingType = $Formatting[24]
149-
$Script = $Formatting[25]
150+
$ShadingType = $Formatting[23]
151+
$Script = $Formatting[24]
152+
$Style = $Formatting[25]
150153
}
151154

152155
$Paragraph = $Paragraph | Set-WordTextColor -Color $Color[$i] -Supress $false
@@ -175,6 +178,7 @@
175178
$Paragraph = $Paragraph | Set-WordTextIndentationHanging -IndentationHanging $IndentationHanging[$i] -Supress $false
176179
$Paragraph = $Paragraph | Set-WordTextAlignment -Alignment $Alignment[$i] -Supress $false
177180
$Paragraph = $Paragraph | Set-WordTextDirection -Direction $Direction[$i] -Supress $false
181+
$Paragraph = $Paragraph | Set-WordTextStyle -StyleName $Style[$i] -Supress $false
178182
}
179183

180184
if ($Supress) { return } else { return $Paragraph }

Public/Paragraph/Set-WordText.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
[alias ("CA")] [Xceed.Document.NET.CapsStyle[]] $CapsStyle = @(),
1818
[alias ("ST")] [Xceed.Document.NET.StrikeThrough[]] $StrikeThrough = @(),
1919
[alias ("HT")] [Xceed.Document.NET.HeadingType[]] $HeadingType = @(),
20+
[string[]] $Style = @(),
2021
[int[]] $PercentageScale = @(), # "Value must be one of the following: 200, 150, 100, 90, 80, 66, 50 or 33"
2122
[Xceed.Document.NET.Misc[]] $Misc = @(),
2223
[string[]] $Language = @(),
@@ -82,5 +83,6 @@
8283
$Paragraph[$i] = $Paragraph[$i] | Set-WordTextIndentationHanging -IndentationHanging $IndentationHanging[$i] -Supress $false
8384
$Paragraph[$i] = $Paragraph[$i] | Set-WordTextAlignment -Alignment $Alignment[$i] -Supress $false
8485
$Paragraph[$i] = $Paragraph[$i] | Set-WordTextDirection -Direction $Direction[$i] -Supress $false
86+
$Paragraph[$i] = $Paragraph[$i] | Set-WordTextStyle -StyleName $Style[$i] -Supress $false
8587
}
8688
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function Set-WordTextStyle {
2+
[CmdletBinding()]
3+
param(
4+
[parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Document.NET.InsertBeforeOrAfter] $Paragraph,
5+
[string] $StyleName,
6+
[bool] $Supress = $false
7+
)
8+
if ($null -ne $Paragraph -and $null -ne $StyleName) {
9+
Write-Verbose "Set-WordTextStyle - Setting StyleName to $StyleName"
10+
$Paragraph.StyleName = $StyleName
11+
}
12+
if ($Supress) { return } else { return $Paragraph }
13+
}

0 commit comments

Comments
 (0)