Skip to content

Commit ea4760b

Browse files
feat: Close-OpenXML ( Fixes #16 )
1 parent b708a4a commit ea4760b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Commands/Close-OpenXML.ps1

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function Close-OpenXML {
2+
<#
3+
.SYNOPSIS
4+
Closes OpenXML files
5+
.DESCRIPTION
6+
Closes OpenXML files and streams
7+
#>
8+
param(
9+
[Parameter(ValueFromPipeline)]
10+
[PSObject]
11+
$InputObject
12+
)
13+
14+
process {
15+
if (-not $InputObject) { return }
16+
if ($InputObject -isnot [IO.Packaging.Package]) { return }
17+
if ($InputObject.MemoryStream) {
18+
try {
19+
$InputObject.MemoryStream.Close()
20+
} catch {
21+
$PSCmdlet.WriteError($_)
22+
}
23+
}
24+
25+
try {
26+
$InputObject.Close()
27+
} catch {
28+
$PSCmdlet.WriteError($_)
29+
}
30+
}
31+
32+
}

0 commit comments

Comments
 (0)