Skip to content

Commit dbe0629

Browse files
add word interop dll (#114)
* use install script to get word dll * update deploy action to rename secret name
1 parent fe528f8 commit dbe0629

File tree

5 files changed

+160
-108
lines changed

5 files changed

+160
-108
lines changed

.github/workflows/Deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ jobs:
8787
git push
8888
- name: Publish To Gallery
8989
env:
90-
API_KEY: ${{ secrets.API_KEY }}
90+
API_KEY: ${{ secrets.POWERSHELL_GALLERY_API_KEY}}
9191
run: |
9292
if(!(Test-Path StagingChangedModules)) {
9393
Write-Host "No modules changed"

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## Ignore Visual Studio temporary files, build results, and
22
## files generated by popular Visual Studio add-ons.
33

4+
# The folder that the install.ps1 for the Word module uses for adding dependencies
5+
WordInteropNugetPackage/
6+
47
# User-specific files
58
*.suo
69
*.user

Modules/IntelliTect.MicrosoftWord/IntelliTect.MicrosoftWord.psd1

+86-86
Original file line numberDiff line numberDiff line change
@@ -3,136 +3,136 @@
33
#
44
# Generated by: Mark Michaelis, Kelly Adams
55
#
6-
# Generated on: 10/31/2022
6+
# Generated on: 12/14/2022
77
#
88

99
@{
1010

11-
# Script module or binary module file associated with this manifest.
12-
RootModule = './IntelliTect.MicrosoftWord.psm1'
11+
# Script module or binary module file associated with this manifest.
12+
RootModule = './IntelliTect.MicrosoftWord.psm1'
1313

14-
# Version number of this module.
15-
ModuleVersion = '0.5.0.3'
14+
# Version number of this module.
15+
ModuleVersion = '0.5.0.3'
1616

17-
# Supported PSEditions
18-
# CompatiblePSEditions = @()
17+
# Supported PSEditions
18+
# CompatiblePSEditions = @()
1919

20-
# ID used to uniquely identify this module
21-
GUID = '46f84048-02ed-4a12-8ec5-00be86a95abb'
20+
# ID used to uniquely identify this module
21+
GUID = '46f84048-02ed-4a12-8ec5-00be86a95abb'
2222

23-
# Author of this module
24-
Author = 'Mark Michaelis, Kelly Adams'
23+
# Author of this module
24+
Author = 'Mark Michaelis, Kelly Adams'
2525

26-
# Company or vendor of this module
27-
CompanyName = 'IntelliTect'
26+
# Company or vendor of this module
27+
CompanyName = 'IntelliTect'
2828

29-
# Copyright statement for this module
30-
Copyright = '(c) Mark Michaelis, Kelly Adams. All rights reserved.'
29+
# Copyright statement for this module
30+
Copyright = '(c) Mark Michaelis, Kelly Adams. All rights reserved.'
3131

32-
# Description of the functionality provided by this module
33-
Description = 'Provides an easy-to-use interface to Microsoft Word via PowerShell.'
32+
# Description of the functionality provided by this module
33+
Description = 'Provides an easy-to-use interface to Microsoft Word via PowerShell.'
3434

35-
# Minimum version of the PowerShell engine required by this module
36-
# PowerShellVersion = ''
35+
# Minimum version of the PowerShell engine required by this module
36+
# PowerShellVersion = ''
3737

38-
# Name of the PowerShell host required by this module
39-
# PowerShellHostName = ''
38+
# Name of the PowerShell host required by this module
39+
# PowerShellHostName = ''
4040

41-
# Minimum version of the PowerShell host required by this module
42-
# PowerShellHostVersion = ''
41+
# Minimum version of the PowerShell host required by this module
42+
# PowerShellHostVersion = ''
4343

44-
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
45-
# DotNetFrameworkVersion = ''
44+
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
45+
# DotNetFrameworkVersion = ''
4646

47-
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
48-
# ClrVersion = ''
47+
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
48+
# ClrVersion = ''
4949

50-
# Processor architecture (None, X86, Amd64) required by this module
51-
# ProcessorArchitecture = ''
50+
# Processor architecture (None, X86, Amd64) required by this module
51+
# ProcessorArchitecture = ''
5252

53-
# Modules that must be imported into the global environment prior to importing this module
54-
# RequiredModules = @()
53+
# Modules that must be imported into the global environment prior to importing this module
54+
# RequiredModules = @()
5555

56-
# Assemblies that must be loaded prior to importing this module
57-
# RequiredAssemblies = @()
56+
# Assemblies that must be loaded prior to importing this module
57+
#RequiredAssemblies = @()
5858

59-
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
60-
# ScriptsToProcess = @()
59+
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
60+
ScriptsToProcess = @("install.ps1")
6161

62-
# Type files (.ps1xml) to be loaded when importing this module
63-
# TypesToProcess = @()
62+
# Type files (.ps1xml) to be loaded when importing this module
63+
# TypesToProcess = @()
6464

65-
# Format files (.ps1xml) to be loaded when importing this module
66-
# FormatsToProcess = @()
65+
# Format files (.ps1xml) to be loaded when importing this module
66+
# FormatsToProcess = @()
6767

68-
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
69-
# NestedModules = @()
68+
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
69+
# NestedModules = @()
7070

71-
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72-
FunctionsToExport = 'Test-FileIsLocked', 'Open-MicrosoftWord', 'Open-WordDocument',
73-
'Get-WordDocumentComment', 'Update-WordDocumentAcceptAllChanges',
74-
'Set-WordDocumentTrackChanges', 'Get-WordDocumentTrackChanges',
75-
'Set-WordDocumentProtection', 'Invoke-WordDocumentFindReplace',
76-
'Invoke-WordDocumentFind', 'Compare-WordDocument',
77-
'Get-WordDocumentProperty', 'Set-WordDocumentProperty',
78-
'Get-WordDocumentTemplate', 'Set-WordDocumentTemplate'
71+
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72+
FunctionsToExport = 'Test-FileIsLocked', 'Open-MicrosoftWord', 'Open-WordDocument',
73+
'Get-WordDocumentComment', 'Update-WordDocumentAcceptAllChanges',
74+
'Set-WordDocumentTrackChanges', 'Get-WordDocumentTrackChanges',
75+
'Set-WordDocumentProtection', 'Invoke-WordDocumentFindReplace',
76+
'Invoke-WordDocumentFind', 'Compare-WordDocument',
77+
'Get-WordDocumentProperty', 'Set-WordDocumentProperty',
78+
'Get-WordDocumentTemplate', 'Set-WordDocumentTemplate'
7979

80-
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
81-
CmdletsToExport = '*'
80+
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
81+
CmdletsToExport = '*'
8282

83-
# Variables to export from this module
84-
VariablesToExport = '*'
83+
# Variables to export from this module
84+
VariablesToExport = '*'
8585

86-
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
87-
AliasesToExport = '*'
86+
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
87+
AliasesToExport = '*'
8888

89-
# DSC resources to export from this module
90-
# DscResourcesToExport = @()
89+
# DSC resources to export from this module
90+
# DscResourcesToExport = @()
9191

92-
# List of all modules packaged with this module
93-
# ModuleList = @()
92+
# List of all modules packaged with this module
93+
# ModuleList = @()
9494

95-
# List of all files packaged with this module
96-
# FileList = @()
95+
# List of all files packaged with this module
96+
# FileList = @()
9797

98-
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
99-
PrivateData = @{
98+
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
99+
PrivateData = @{
100100

101-
PSData = @{
101+
PSData = @{
102102

103-
# Tags applied to this module. These help with module discovery in online galleries.
104-
# Tags = @()
103+
# Tags applied to this module. These help with module discovery in online galleries.
104+
# Tags = @()
105105

106-
# A URL to the license for this module.
107-
# LicenseUri = ''
106+
# A URL to the license for this module.
107+
# LicenseUri = ''
108108

109-
# A URL to the main website for this project.
110-
# ProjectUri = ''
109+
# A URL to the main website for this project.
110+
# ProjectUri = ''
111111

112-
# A URL to an icon representing this module.
113-
# IconUri = ''
112+
# A URL to an icon representing this module.
113+
# IconUri = ''
114114

115-
# ReleaseNotes of this module
116-
# ReleaseNotes = ''
115+
# ReleaseNotes of this module
116+
# ReleaseNotes = ''
117117

118-
# Prerelease string of this module
119-
# Prerelease = ''
118+
# Prerelease string of this module
119+
# Prerelease = ''
120120

121-
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
122-
# RequireLicenseAcceptance = $false
121+
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
122+
# RequireLicenseAcceptance = $false
123123

124-
# External dependent modules of this module
125-
# ExternalModuleDependencies = @()
124+
# External dependent modules of this module
125+
# ExternalModuleDependencies = @()
126126

127-
} # End of PSData hashtable
127+
} # End of PSData hashtable
128128

129-
} # End of PrivateData hashtable
129+
} # End of PrivateData hashtable
130130

131-
# HelpInfo URI of this module
132-
# HelpInfoURI = ''
131+
# HelpInfo URI of this module
132+
# HelpInfoURI = ''
133133

134-
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
135-
# DefaultCommandPrefix = ''
134+
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
135+
# DefaultCommandPrefix = ''
136136

137137
}
138138

Modules/IntelliTect.MicrosoftWord/IntelliTect.MicrosoftWord.psm1

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
21
try {
32
add-type -AssemblyName 'Microsoft.Office.Interop.Word'
43
}
54
catch {
65
try {
7-
$wordAssemblyPath = Resolve-Path "$(${env:ProgramFiles(x86)})\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA\Office*\Microsoft.Office.Interop.Word.dll" | `
6+
# the install location of the dll as per install.ps1
7+
$wordAssemblyPath = Resolve-Path "./Lib/WordInteropNugetPackage/lib/netstandard2.0/Microsoft.Office.Interop.Word.dll" | `
88
Sort-Object -Descending | Select-Object -First 1
9-
if($wordAssemblyPath -and (Test-Path $wordAssemblyPath)) {
9+
if ($wordAssemblyPath -and (Test-Path $wordAssemblyPath)) {
1010
add-type -Path $wordAssemblyPath
1111
}
1212
else {
@@ -453,7 +453,7 @@ Function script:Invoke-WordDocumentInternalFindReplace {
453453
[string]$findResult = $null;
454454

455455
# Invoke Callback
456-
if($OnFindCommand) {
456+
if ($OnFindCommand) {
457457
Invoke-Command $OnFindCommand -ArgumentList $selection
458458
}
459459

@@ -730,9 +730,9 @@ Function Invoke-WordDocumentFindReplace {
730730
#>
731731
Function Invoke-WordDocumentFind {
732732
[OutputType('WordDocument.FindResult')]
733-
[CmdletBinding(DefaultParameterSetName='Path')] param(
733+
[CmdletBinding(DefaultParameterSetName = 'Path')] param(
734734
[ValidateScript( { Test-Path $_ -PathType Leaf })]
735-
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName, Position, ParameterSetName='Path')]
735+
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName, Position, ParameterSetName = 'Path')]
736736
[Alias("FullName", "InputObject")]
737737
[string[]]$Path,
738738
# An open instance of a word document (returned from Open-WordDocument)
@@ -753,14 +753,14 @@ Function Invoke-WordDocumentFind {
753753

754754
PROCESS {
755755
Function Invoke-Find {
756-
[CmdletBinding()]
757-
param([object]$EachDocument)
756+
[CmdletBinding()]
757+
param([object]$EachDocument)
758758

759759

760760
Write-Progress -Activity "Invoke-WordDocumentFind" -Status $_
761761
Write-Progress -Activity "Invoke-WordDocumentFind" -Status $_ -CurrentOperation "Find: $Value"
762762

763-
<#
763+
<#
764764
BLOG-THIS:
765765
We wasnt to set visible to true when debugging or when -Debug specified.
766766
Unfortunately, the following doesn't work:
@@ -777,23 +777,23 @@ Function Invoke-WordDocumentFind {
777777
#>
778778

779779

780-
# Use empty string for replace value since we are not replacing with anything.
781-
$findResults = script:Invoke-WordDocumentInternalFindReplace -document $EachDocument `
782-
-findValue $value -matchCase $matchCase -matchWholeWord $matchWholeWord `
783-
-matchWildcards $matchWildcards -matchSoundsLike $matchSoundsLike `
784-
-matchAllWordForms $matchAllWordForms -OnFindCommand $OnFindCommand
780+
# Use empty string for replace value since we are not replacing with anything.
781+
$findResults = script:Invoke-WordDocumentInternalFindReplace -document $EachDocument `
782+
-findValue $value -matchCase $matchCase -matchWholeWord $matchWholeWord `
783+
-matchWildcards $matchWildcards -matchSoundsLike $matchSoundsLike `
784+
-matchAllWordForms $matchAllWordForms -OnFindCommand $OnFindCommand
785785

786-
if (@($findResults).Count -gt 0) {
787-
#$result = ([pscustomobject]@{Document = Get-Item $documentPath; Snippets = $textSnippets.Before})
788-
#$textSnippets | Get-Member
789-
$findResults | Write-Output
790-
}
786+
if (@($findResults).Count -gt 0) {
787+
#$result = ([pscustomobject]@{Document = Get-Item $documentPath; Snippets = $textSnippets.Before})
788+
#$textSnippets | Get-Member
789+
$findResults | Write-Output
790+
}
791791
}
792792

793793
Write-Progress -Activity "Invoke-WordDocumentFind" -PercentComplete 0
794794

795-
if($PSCmdlet.ParameterSetName -eq 'Document') {
796-
$WordDocument | ForEach-Object{
795+
if ($PSCmdlet.ParameterSetName -eq 'Document') {
796+
$WordDocument | ForEach-Object {
797797
Invoke-Find -EachDocument $_
798798
}
799799
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
# get the latest word interop package and place the dll in the lib folder
3+
$wordInteropNugetDownloadUrl = "https://www.nuget.org/api/v2/package/Microsoft.Office.Interop.Word"
4+
5+
$ZipFile = "./" + $(Split-Path -Path $wordInteropNugetDownloadUrl -Leaf) + ".zip"
6+
7+
$ExtractPath = "./Lib/WordInteropNugetPackage"
8+
9+
Invoke-WebRequest -Uri $wordInteropNugetDownloadUrl -OutFile $ZipFile
10+
11+
Expand-Archive -Path $ZipFile -DestinationPath $ExtractPath
12+
13+
Remove-Item $ZipFile
14+
15+
# ensure word is installed
16+
17+
try {
18+
add-type -AssemblyName 'Microsoft.Office.Interop.Word'
19+
}
20+
catch {
21+
try {
22+
# the install location of the dll as per install.ps1
23+
$wordAssemblyPath = Resolve-Path "./Lib/WordInteropNugetPackage/lib/netstandard2.0/Microsoft.Office.Interop.Word.dll" | `
24+
Sort-Object -Descending | Select-Object -First 1
25+
if ($wordAssemblyPath -and (Test-Path $wordAssemblyPath)) {
26+
add-type -Path $wordAssemblyPath
27+
}
28+
else {
29+
throw;
30+
}
31+
}
32+
catch {
33+
throw 'Error with install script. Unable to find Microsoft.Office.Interop.Word package (see https://www.nuget.org/packages/Microsoft.Office.Interop.Word)'
34+
}
35+
}
36+
37+
Write-Output "Microsoft.Office.Interop.Word installed for module."
38+
39+
try {
40+
# check if word is installed
41+
$Word = New-Object -ComObject word.application
42+
$Word.Quit([Microsoft.Office.Interop.Word.WdSaveOptions]::wdDoNotSaveChanges)
43+
}
44+
catch {
45+
throw 'Unable to find Microsoft Word. You must have an install of Microsoft Word in order to use this module.'
46+
}
47+
Write-Output "Microsoft Word is installed. (Module requires existing Word Installation)"
48+
49+
Write-Output "Ready to go!"

0 commit comments

Comments
 (0)