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

Commit 3f9fac7

Browse files
Fixes #69 by defining defaults
1 parent 80897c0 commit 3f9fac7

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed
Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
function Set-WordTextReplace {
22
<#
33
.SYNOPSIS
4-
Short description
4+
Provides ability to search and replace certain words, phrases, or regular expressions in a word file.
55
66
.DESCRIPTION
7-
Long description
7+
Provides ability to search and replace certain words, phrases, or regular expressions in a word file.
88
99
.PARAMETER Paragraph
10-
Parameter description
10+
Provide paragraph to search for text
1111
1212
.PARAMETER SearchValue
13-
Parameter description
13+
Value to search for
1414
1515
.PARAMETER ReplaceValue
16-
Parameter description
16+
Value to replace with
1717
1818
.PARAMETER TrackChanges
19-
Track changes
19+
Track changes, default is off
2020
2121
.PARAMETER RegexOptions
22-
Parameter description
22+
The regex options to use when searching for the search value. Default is none.
2323
2424
.PARAMETER NewFormatting
2525
The formatting to apply to the text being inserted.
@@ -28,7 +28,7 @@
2828
The formatting that the text must match in order to be replaced.
2929
3030
.PARAMETER MatchFormattingOptions
31-
How should formatting be matched?
31+
How should formatting be matched? ExactMatch (default) or SubsetMatch
3232
3333
.PARAMETER escapeRegEx
3434
True if the oldValue needs to be escaped, otherwise false. If it represents a valid RegEx pattern this should be false.
@@ -40,21 +40,30 @@
4040
Remove empty paragraph
4141
4242
.EXAMPLE
43-
An example
43+
$FilePath = "C:\Users\przemyslaw.klys\OneDrive - Evotec\Desktop\Word.docx"
44+
$FilePath1 = "C:\Users\przemyslaw.klys\OneDrive - Evotec\Desktop\Word1.docx"
45+
$doc = Get-WordDocument -FilePath $FilePath
46+
$word = "Sample"
47+
$formatObj = New-Object Xceed.Document.NET.Formatting
48+
$formatObj.FontColor = "Red"
49+
foreach ($p in $doc.Paragraphs) {
50+
Set-WordTextReplace -Paragraph $p -SearchValue $word -ReplaceValue $word -NewFormatting $formatObj -Supress $false
51+
}
52+
Save-WordDocument -Document $doc -FilePath $FilePath1
4453
4554
.NOTES
4655
General notes
4756
#>
4857
[CmdletBinding()]
4958
param(
50-
[parameter(ValueFromPipelineByPropertyName, ValueFromPipeline)][Xceed.Document.NET.InsertBeforeOrAfter] $Paragraph,
59+
[parameter(ValueFromPipelineByPropertyName, ValueFromPipeline, Mandatory)][Xceed.Document.NET.InsertBeforeOrAfter] $Paragraph,
5160
[string] $SearchValue,
52-
[string] $ReplaceValue,
61+
[alias('NewValue')][string] $ReplaceValue,
5362
[switch] $TrackChanges,
54-
[System.Text.RegularExpressions.RegexOptions] $RegexOptions,
55-
[Xceed.Document.NET.Formatting] $NewFormatting,
56-
[Xceed.Document.NET.Formatting] $MatchFormatting,
57-
[Xceed.Document.NET.MatchFormattingOptions] $MatchFormattingOptions,
63+
[System.Text.RegularExpressions.RegexOptions] $RegexOptions = [System.Text.RegularExpressions.RegexOptions]::None,
64+
[Xceed.Document.NET.Formatting] $NewFormatting = [Xceed.Document.NET.Formatting]::new(),
65+
[Xceed.Document.NET.Formatting] $MatchFormatting = [Xceed.Document.NET.Formatting]::new(),
66+
[Xceed.Document.NET.MatchFormattingOptions] $MatchFormattingOptions = [Xceed.Document.NET.MatchFormattingOptions]::ExactMatch,
5867
[switch] $EscapeRegEx,
5968
[switch] $UseRegExSubstitutions,
6069
[switch] $RemoveEmptyParagraph,
@@ -64,7 +73,6 @@
6473
#void ReplaceText(string findPattern, System.Func[string,string] regexMatchHandler, bool trackChanges, System.Text.RegularExpressions.RegexOptions options, Xceed.Document.NET.Formatting newFormatting, Xceed.Document.NET.Formatting matchFormatting, Xceed.Document.NET.MatchFormattingOptions fo, bool removeEmptyParagraph)
6574
if ($Paragraph) {
6675
$Paragraph = $Paragraph.ReplaceText($SearchValue, $ReplaceValue, $TrackChanges.IsPresent, $RegexOptions, $NewFormatting, $matchFormatting, $MatchFormattingOptions, $EscapeRegEx.IsPresent, $UseRegExSubstitutions.IsPresent, $RemoveEmptyParagraph.IsPresent)
67-
if ($Supress) { return } else { return $Paragraph }
76+
if ($Suppress) { return } else { return $Paragraph }
6877
}
69-
#$Paragraph.ReplaceText($SearchValue, $ReplaceValue, $TrackChanges, $RegexOptions, $NewFormatting, $MatchFormatting, $MatchFormattingOptions, $escapeRegEx, $useRegExSubstitutions, $removeEmptyParagraph)
7078
}

0 commit comments

Comments
 (0)