Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Commands/Get-OpenXML.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function Get-OpenXML
[Alias('OpenXML')]
param(
# The path to the OpenXML file to read
[Parameter(ValueFromPipelineByPropertyName=$true)]
[Parameter(ValueFromPipelineByPropertyName)]
[Alias('Fullname')]
[string]
$FilePath
Expand Down Expand Up @@ -46,33 +46,34 @@ function Get-OpenXML

$filePackage.pstypenames.insert(0,'OpenXML')
$filePackage.pstypenames.insert(0,'OpenXML.File')
$packageContent = $filePackage.Parts
$openXMLObject = $filePackage |
Add-Member NoteProperty FilePath $filePath -Force -PassThru |
Add-Member NoteProperty MemoryStream $memoryStream -Force -PassThru

$packageParts = $filePackage.GetParts()

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

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

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

# If the package contains a part with `/Documents/` in the URI,
if ($filePackage.Parts.Keys -match '/Documents/') {
if ($packageParts.Uri -match '^Documents/') {
# it is an `OpenXML.XPS.File`
$openXmlObject.pstypenames.insert(0, 'OpenXML.XPS.File')
}
Expand Down
2 changes: 1 addition & 1 deletion OpenXML.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ PrivateData = @{
PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('Word','Excel','PowerPoint','OpenXML','Office Open XML','OOXML')
Tags = @('Word','Excel','PowerPoint','OpenXML','OfficeOpenXML','OOXML')

# A URL to the license for this module.
LicenseUri = 'https://github.com/PowerShellWeb/OpenXML/blob/main/LICENSE'
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# OpenXML
## Automate OpenXML. Excel, Word, and PowerPoint automation in PowerShell.
<div align='center'>
<a href='https://www.powershellgallery.com/packages/OpenXML/' >
<img src='https://img.shields.io/powershellgallery/dt/OpenXML' />
</a>
</div>

OpenXML is the standard used for Office documents.

Expand Down
8 changes: 8 additions & 0 deletions README.md.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ This module is here to help you automate, inspect, and understand OpenXML files.

"## $($ThisModule.Description)"

@"
<div align='center'>
<a href='https://www.powershellgallery.com/packages/OpenXML/' >
<img src='https://img.shields.io/powershellgallery/dt/OpenXML' />
</a>
</div>
"@

$intro

"### Installing and Importing"
Expand Down
Loading