Skip to content

Commit a972b48

Browse files
feat: OpenXML.Word.File.get_Style ( Fixes #61 )
1 parent 0ab5a3f commit a972b48

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<#
2+
.SYNOPSIS
3+
Gets word file styles
4+
.DESCRIPTION
5+
Gets the `/word/styles.xml` within a Word File.
6+
#>
7+
[OutputType([xml])]
8+
param()
9+
10+
if ($null -ne $this.'#style') { return $this.'#style'}
11+
12+
if (-not $this.PartExists) { return }
13+
if (-not $this.PartExists('/word/styles.xml')) { return }
14+
15+
$documentPart = $this.GetPart('/word/styles.xml')
16+
17+
$docStream = $documentPart.GetStream()
18+
19+
$streamReader = [IO.StreamReader]::new($docStream)
20+
21+
$stylesXml = $streamReader.ReadToEnd() -as [xml]
22+
23+
$streamReader.Close()
24+
$streamReader.Dispose()
25+
26+
$docStream.Close()
27+
$docStream.Dispose()
28+
29+
if ($stylesXml) {
30+
$stylesXml.pstypenames.insert(0,'OpenXML.Word.Style')
31+
$stylesXml.psobject.properties.add(
32+
[psnoteproperty]::new('FilePath', $this.FilePath), $false
33+
)
34+
$stylesXml.psobject.properties.add(
35+
[psnoteproperty]::new('OpenXML', $this), $false
36+
)
37+
$stylesXml.psobject.properties.add(
38+
[psnoteproperty]::new('Part', $documentPart), $false
39+
)
40+
$this.psobject.properties.add(
41+
[psnoteproperty]::new('#style', $stylesXml), $false
42+
)
43+
return $this.'#styles'
44+
}
45+

0 commit comments

Comments
 (0)