Skip to content

Commit 1a8fee6

Browse files
fix: Get-OpenXML improvement ( Fixes #2 )
Using .GetParts to check document type
1 parent aedbbb7 commit 1a8fee6

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Commands/Get-OpenXML.ps1

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Get-OpenXML
1818
[Alias('OpenXML')]
1919
param(
2020
# The path to the OpenXML file to read
21-
[Parameter(ValueFromPipelineByPropertyName=$true)]
21+
[Parameter(ValueFromPipelineByPropertyName)]
2222
[Alias('Fullname')]
2323
[string]
2424
$FilePath
@@ -46,33 +46,34 @@ function Get-OpenXML
4646

4747
$filePackage.pstypenames.insert(0,'OpenXML')
4848
$filePackage.pstypenames.insert(0,'OpenXML.File')
49-
$packageContent = $filePackage.Parts
5049
$openXMLObject = $filePackage |
5150
Add-Member NoteProperty FilePath $filePath -Force -PassThru |
5251
Add-Member NoteProperty MemoryStream $memoryStream -Force -PassThru
52+
53+
$packageParts = $filePackage.GetParts()
5354

5455
# Now we can get more specific about what type of OpenXML file this is.
5556
# By looking for certain key parts, we can determine if this is a PowerPoint, Excel, or Word file.
5657
# For example, if the package contains a part with `/ppt/` in the URI,
57-
if ($filePackage.Parts.Keys -match '/ppt/') {
58+
if ($packageParts.Uri -match '^/ppt/') {
5859
# it is an `OpenXML.PowerPoint.File`
5960
$openXmlObject.pstypenames.insert(0, 'OpenXML.PowerPoint.File')
6061
}
6162

6263
# If the package contains a part with `/xl/` in the URI,
63-
if ($filePackage.Parts.Keys -match '/xl/') {
64+
if ($packageParts.Uri -match '^/xl/') {
6465
# it is an `OpenXML.Excel.File`
6566
$openXmlObject.pstypenames.insert(0, 'OpenXML.Excel.File')
6667
}
6768

6869
# If the package contains a part with `/word/` in the URI, it is a Word file.
69-
if ($filePackage.Parts.Keys -match '/word/') {
70+
if ($packageParts.Uri -match '^/word/') {
7071
# it is an `OpenXML.Word.File`
7172
$openXmlObject.pstypenames.insert(0, 'OpenXML.Word.File')
7273
}
7374

7475
# If the package contains a part with `/Documents/` in the URI,
75-
if ($filePackage.Parts.Keys -match '/Documents/') {
76+
if ($packageParts.Uri -match '^Documents/') {
7677
# it is an `OpenXML.XPS.File`
7778
$openXmlObject.pstypenames.insert(0, 'OpenXML.XPS.File')
7879
}

0 commit comments

Comments
 (0)