Skip to content

Commit 38d18c3

Browse files
committed
Initial commit of Open-Xml-PowerTools
1 parent 05d6fab commit 38d18c3

File tree

592 files changed

+117191
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

592 files changed

+117191
-3
lines changed

.gitattributes

+11
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,24 @@
77
*.ps1 text
88
*.psm1 text
99
*.psd1 text
10+
*.config text
11+
*.md text
12+
*.txt text
13+
*.xml text
14+
*.resx text
15+
16+
.gitattributes text
17+
.gitignore text
1018

1119
# Declare files that will always have CRLF line endings on checkout.
1220
*.sln text eol=crlf
21+
*.csproj text eol=crlf
1322

1423
# Denote all files that are truly binary and should not be modified.
1524
*.png binary
1625
*.jpg binary
1726
*.docx binary
1827
*.xlsx binary
28+
*.pptx binary
29+
1930

.gitignore

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
*.exe
22
*.pdb
33
*.cache
4-
**/Libs/OpenXmlPowerTools.dll
5-
!Libs/DocumentFormat.OpenXml.dll
6-
!Libs/System.IO.Packaging.dll
4+
*.dll
75

86
# output files from the OpenXmlPowerTools examples
97
**/DocumentAssembler/AssembledDoc.docx
@@ -15,6 +13,9 @@
1513
**/TextReplacer01/*out*
1614
**/SpreadsheetWriter01/Test1.xlsx
1715
**/SpreadsheetWriter02/Test2.xlsx
16+
**/PivotTables01/NewPivot.xlsx
17+
**/PivotTables01/QuarterlyPivot.xlsx
18+
**/PivotTables01/QuarterlyUnitSalesWithPivot.xlsx
1819

1920
*.suo
2021
*.user

AddTypes.ps1

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<#***************************************************************************
2+
3+
Copyright (c) Microsoft Corporation 2014.
4+
5+
This code is licensed using the Microsoft Public License (Ms-PL). The text of the license can be found here:
6+
7+
http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx
8+
9+
Published at http://OpenXmlDeveloper.org
10+
Resource Center and Documentation: http://openxmldeveloper.org/wiki/w/wiki/powertools-for-open-xml.aspx
11+
12+
Developer: Eric White
13+
Blog: http://www.ericwhite.com
14+
Twitter: @EricWhiteDev
15+
16+
17+
Version: 3.0.0
18+
19+
***************************************************************************#>
20+
21+
$assemblies = (
22+
"$PSScriptRoot\..\..\..\Open-Xml-Sdk\DocumentFormat.OpenXml\bin\debug\DocumentFormat.OpenXml.dll",
23+
"$PSScriptRoot\..\..\..\Open-Xml-Sdk\DocumentFormat.OpenXml\bin\debug\System.IO.Packaging.dll",
24+
"System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
25+
"System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
26+
"System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
27+
"System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
28+
"System.IO.Compression, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
29+
)
30+
31+
$sources = @(
32+
"$PSScriptRoot\OpenXmlPowerTools\DocumentAssembler.cs",
33+
"$PSScriptRoot\OpenXmlPowerTools\DocumentBuilder.cs",
34+
"$PSScriptRoot\OpenXmlPowerTools\ExcelFormula.cs",
35+
"$PSScriptRoot\OpenXmlPowerTools\FieldRetriever.cs",
36+
"$PSScriptRoot\OpenXmlPowerTools\FormattingAssembler.cs",
37+
"$PSScriptRoot\OpenXmlPowerTools\GetListItemText_Default.cs",
38+
"$PSScriptRoot\OpenXmlPowerTools\GetListItemText_fr_FR.cs",
39+
"$PSScriptRoot\OpenXmlPowerTools\GetListItemText_ru_RU.cs",
40+
"$PSScriptRoot\OpenXmlPowerTools\GetListItemText_sv_SE.cs",
41+
"$PSScriptRoot\OpenXmlPowerTools\GetListItemText_tr_TR.cs",
42+
"$PSScriptRoot\OpenXmlPowerTools\GetListItemText_zh_CN.cs",
43+
"$PSScriptRoot\OpenXmlPowerTools\HtmlConverter.cs",
44+
"$PSScriptRoot\OpenXmlPowerTools\ListItemRetriever.cs",
45+
"$PSScriptRoot\OpenXmlPowerTools\MarkupSimplifier.cs",
46+
"$PSScriptRoot\OpenXmlPowerTools\MetricsGetter.cs",
47+
"$PSScriptRoot\OpenXmlPowerTools\OpenXmlRegex.cs",
48+
"$PSScriptRoot\OpenXmlPowerTools\OxPtHelpers.cs",
49+
"$PSScriptRoot\OpenXmlPowerTools\PegBase.cs",
50+
"$PSScriptRoot\OpenXmlPowerTools\PresentationBuilder.cs",
51+
"$PSScriptRoot\OpenXmlPowerTools\PtOpenXmlDocument.cs",
52+
"$PSScriptRoot\OpenXmlPowerTools\PtOpenXmlUtil.cs",
53+
"$PSScriptRoot\OpenXmlPowerTools\PtUtil.cs",
54+
"$PSScriptRoot\OpenXmlPowerTools\ReferenceAdder.cs",
55+
"$PSScriptRoot\OpenXmlPowerTools\RevisionAccepter.cs",
56+
"$PSScriptRoot\OpenXmlPowerTools\SSFormula.cs",
57+
"$PSScriptRoot\OpenXmlPowerTools\SpreadsheetWriter.cs",
58+
"$PSScriptRoot\OpenXmlPowerTools\TextReplacer.cs",
59+
"$PSScriptRoot\OpenXmlPowerTools\WmlDocument.cs",
60+
"$PSScriptRoot\OpenXmlPowerTools\WorksheetAccessor.cs",
61+
"$PSScriptRoot\OpenXmlPowerTools\XlsxTables.cs",
62+
"$PSScriptRoot\OpenXmlPowerTools\OpenXmlCmdlet.cs",
63+
"$PSScriptRoot\OpenXmlPowerTools\SpreadsheetDocumentManager.cs",
64+
"$PSScriptRoot\OpenXmlPowerTools\OutXlsxCmdlet.cs",
65+
"$PSScriptRoot\OpenXmlPowerTools\ScalarTypes.cs"
66+
)
67+
68+
Add-Type -Path "$PSScriptRoot\..\..\..\Open-Xml-Sdk\DocumentFormat.OpenXml\bin\debug\DocumentFormat.OpenXml.dll"
69+
Add-Type -Path "$PSScriptRoot\..\..\..\Open-Xml-Sdk\DocumentFormat.OpenXml\bin\debug\System.IO.Packaging.dll"
70+
Add-Type -ReferencedAssemblies $assemblies -Path $sources -OutputAssembly "$PSScriptRoot\OpenXmlPowerTools.dll"

Clean.ps1

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Remove-Item .\OpenXmlPowerTools\bin -Recurse -Force -ErrorAction SilentlyContinue
2+
Remove-Item .\OpenXmlPowerTools\obj -Recurse -Force -ErrorAction SilentlyContinue
3+
Remove-Item .\OpenXmlPowerTools.Net35\bin -Recurse -Force -ErrorAction SilentlyContinue
4+
Remove-Item .\OpenXmlPowerTools.Net35\obj -Recurse -Force -ErrorAction SilentlyContinue
5+
Remove-Item .\OpenXmlPowerTools.Tests\bin -Recurse -Force -ErrorAction SilentlyContinue
6+
Remove-Item .\OpenXmlPowerTools.Tests\obj -Recurse -Force -ErrorAction SilentlyContinue
7+
Remove-Item .\OpenXmlPowerTools.Tests.OA\bin -Recurse -Force -ErrorAction SilentlyContinue
8+
Remove-Item .\OpenXmlPowerTools.Tests.OA\obj -Recurse -Force -ErrorAction SilentlyContinue
9+
Remove-Item .\OpenXmlPowerToolsExamples\*\bin -Recurse -Force -ErrorAction SilentlyContinue
10+
Remove-Item .\OpenXmlPowerToolsExamples\*\obj -Recurse -Force -ErrorAction SilentlyContinue
11+
dir *.suo -Recurse -Force | Remove-Item -ErrorAction SilentlyContinue
12+
$d = '.\OpenXmlPowerToolsExamples\ChartUpdater01\Updated-Chart*'
13+
Remove-Item $d -ErrorAction SilentlyContinue
14+
$d = '.\OpenXmlPowerToolsExamples\DocumentAssembler\AssembledDoc*'
15+
Remove-Item $d -ErrorAction SilentlyContinue
16+
$d = '.\OpenXmlPowerToolsExamples\DocumentAssembler01\AssembledDoc*'
17+
Remove-Item $d -ErrorAction SilentlyContinue
18+
$d = '.\OpenXmlPowerToolsExamples\FormattingAssembler01\*out.docx'
19+
Remove-Item $d -ErrorAction SilentlyContinue
20+
$d = '.\OpenXmlPowerToolsExamples\HtmlConverter01\*.html'
21+
Remove-Item $d -ErrorAction SilentlyContinue
22+
$d = '.\OpenXmlPowerToolsExamples\HtmlConverter01\*_files'
23+
Remove-Item $d -Recurse -Force -ErrorAction SilentlyContinue
24+
$d = '.\OpenXmlPowerToolsExamples\TextReplacer01\*out*'
25+
Remove-Item $d -Recurse -Force -ErrorAction SilentlyContinue
26+
Remove-Item OpenXmlPowerTools.dll -ErrorAction SilentlyContinue

Cmdlet-Examples/Empty.docx

11 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[environment]::CurrentDirectory = $(Get-Location)
2+
3+
Copy-Item .\TrackedRevision.docx .\Out-NoTrackedRevisions.docx
4+
Clear-DocxTrackedRevision Out-NoTrackedRevisions.docx
5+
6+
7+
Copy-Item .\TrackedRevision.docx .\Out-NoTrackedRevisions2.docx
8+
Clear-DocxTrackedRevision Out-NoTrackedRevisions*.docx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[environment]::CurrentDirectory = $(Get-Location)
2+
3+
New-Docx WithStyles.docx -Headings -LoadAndSaveUsingWord
4+
Expand-DocxFormatting WithStyles.docx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[environment]::CurrentDirectory = $(Get-Location)
2+
3+
function GetOpenXmlValidationErrorsExample {
4+
param (
5+
[int]$exampleNum
6+
)
7+
switch ($exampleNum) {
8+
1 {
9+
Get-OpenXmlValidationErrors Valid.docx -OfficeVersion 2010 -Verbose
10+
Get-OpenXmlValidationErrors Invalid.docx -OfficeVersion 2007 -Verbose
11+
}
12+
2 {
13+
Get-ChildItem *.xlsx | Get-OpenXmlValidationErrors -Verbose
14+
}
15+
3 {
16+
Get-OpenXmlValidationErrors *.docx -Verbose -OfficeVersion 2010
17+
}
18+
}
19+
}
20+
21+
for ($e = 1; $e -le 3; $e += 1)
22+
{
23+
GetOpenXmlValidationErrorsExample($e)
24+
}

Cmdlet-Examples/Ex-Merge-Docx.ps1

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[environment]::CurrentDirectory = $(Get-Location)
2+
3+
function MergeDocxExample {
4+
param (
5+
[int]$exampleNum
6+
)
7+
switch ($exampleNum) {
8+
1 {
9+
$doc1 = New-Object OpenXmlPowerTools.Source("Input1.docx")
10+
$doc2 = New-Object OpenXmlPowerTools.Source("Input2.docx", $True)
11+
$sources = ($doc1, $doc2)
12+
Merge-Docx -OutputPath Out-Merge01.docx -Sources $sources -Verbose
13+
}
14+
2 {
15+
$doc1 = New-Object OpenXmlPowerTools.Source("Input1.docx", 1, 2, $false)
16+
$doc2 = New-Object OpenXmlPowerTools.Source("Input2.docx", 1, 2, $false)
17+
$sources = ($doc1, $doc2)
18+
Merge-Docx -OutputPath Out-Merge02.docx -Sources $sources -Verbose
19+
}
20+
3 {
21+
$doc1 = New-Object OpenXmlPowerTools.Source("Input1.docx")
22+
$doc2 = New-Object OpenXmlPowerTools.Source("Input2.docx", 1, 2, $false)
23+
$newWml = Merge-Docx -Sources ($doc1, $doc2) -Verbose
24+
$newWml.SaveAs("Out-Merge03.docx");
25+
}
26+
}
27+
}
28+
29+
for ($e = 1; $e -le 3; $e += 1)
30+
{
31+
MergeDocxExample($e)
32+
}

Cmdlet-Examples/Ex-New-Docx.ps1

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
New-Docx Out-1 -Bookmark
2+
New-Docx Out-2.docx -Comment
3+
New-Docx Out-3.docx -CoverPage
4+
New-Docx Out-All.docx -All -LoadAndSaveUsingWord
5+
[OpenXmlPowerTools.WmlDocument]$wml = New-Docx -Bookmark
6+
$wml.SaveAs("Out-4.docx")
7+
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[environment]::CurrentDirectory = $(Get-Location)
2+
3+
function TestOpenXmlValidExample {
4+
param (
5+
[int]$exampleNum
6+
)
7+
switch ($exampleNum) {
8+
1 {
9+
Test-OpenXmlValid Valid.docx -OfficeVersion 2010 -Verbose
10+
Test-OpenXmlValid Invalid.docx -OfficeVersion 2007 -Verbose
11+
}
12+
2 {
13+
Get-ChildItem *.xlsx | Test-OpenXmlValid -Verbose
14+
}
15+
3 {
16+
Test-OpenXmlValid *.docx -Verbose -OfficeVersion 2010
17+
}
18+
}
19+
}
20+
21+
for ($e = 1; $e -le 3; $e += 1)
22+
{
23+
TestOpenXmlValidExample($e)
24+
}

Cmdlet-Examples/Input1.docx

11.6 KB
Binary file not shown.

Cmdlet-Examples/Input2.docx

11.4 KB
Binary file not shown.

Cmdlet-Examples/Invalid.docx

11.6 KB
Binary file not shown.

Cmdlet-Examples/Invalid2.docx

11.9 KB
Binary file not shown.

Cmdlet-Examples/Template.docx

17.6 KB
Binary file not shown.

Cmdlet-Examples/TemplateData.xml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<Data>
2+
<Name>Eric White</Name>
3+
<Age>53</Age>
4+
</Data>

Cmdlet-Examples/Test.xlsx

6.03 KB
Binary file not shown.

Cmdlet-Examples/TrackedRevision.docx

12.3 KB
Binary file not shown.

Cmdlet-Examples/Valid.docx

11.6 KB
Binary file not shown.

Cmdlets/Add-DocxText.ps1

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<#***************************************************************************
2+
3+
Copyright (c) Microsoft Corporation 2014.
4+
5+
This code is licensed using the Microsoft Public License (Ms-PL). The text of the license can be found here:
6+
7+
http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx
8+
9+
Published at http://OpenXmlDeveloper.org
10+
Resource Center and Documentation: http://openxmldeveloper.org/wiki/w/wiki/powertools-for-open-xml.aspx
11+
12+
***************************************************************************#>
13+
14+
function Add-DocxText {
15+
16+
<#
17+
.SYNOPSIS
18+
Appends given text to a specified DOCX document.
19+
.DESCRIPTION
20+
Add-DocxText cmdlet appends given text to a specified DOCX document. Supports adding text with
21+
bold, italic, underline, forecolor, backcolor, paragraph style.
22+
.EXAMPLE
23+
# Simple use
24+
$fn = "Doc1.docx"
25+
New-Docx $fn -Empty
26+
$fn = Resolve-Path $fn
27+
$w = New-WmlDocument $fn
28+
Add-DocxText $w "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor"
29+
$w.Save()
30+
.EXAMPLE
31+
# Demonstrates adding text with variety of styles / colors
32+
$fn = "Doc1.docx"
33+
New-Docx $fn -Empty
34+
$fn = Resolve-Path $fn
35+
$w = New-WmlDocument $fn
36+
Add-DocxText $w "Title of Document" -Style Title
37+
Add-DocxText $w "Heading" -Style Heading1
38+
Add-DocxText $w "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor"
39+
Add-DocxText $w "Bold Text" -Bold
40+
Add-DocxText $w "Italic Text" -Italic
41+
Add-DocxText $w "Heading2" -Style Heading2
42+
Add-DocxText $w "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor"
43+
$w.Save()
44+
.EXAMPLE
45+
# Demonstrates adding text with forecolor
46+
$fn = "Doc1.docx"
47+
New-Docx $fn -Empty
48+
$fn = Resolve-Path $fn
49+
$w = New-WmlDocument $fn
50+
Add-DocxText $w "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor" -ForeColor Red
51+
$w.Save()
52+
.EXAMPLE
53+
# Demonstrates adding text with backcolor
54+
$fn = "Doc1.docx"
55+
New-Docx $fn -Empty
56+
$fn = Resolve-Path $fn
57+
$w = New-WmlDocument $fn
58+
Add-DocxText $w "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor" -BackColor Green
59+
$w.Save()
60+
.EXAMPLE
61+
# Demonstrates adding text with bold, italic, underline
62+
$fn = "Doc1.docx"
63+
New-Docx $fn -Empty
64+
$fn = Resolve-Path $fn
65+
$w = New-WmlDocument $fn
66+
Add-DocxText $w "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor" -Bold -Italic -Underline
67+
$w.Save()
68+
.EXAMPLE
69+
# Demonstrates adding text with forecolor, backcolor
70+
$fn = "Doc1.docx"
71+
New-Docx $fn -Empty
72+
$fn = Resolve-Path $fn
73+
$w = New-WmlDocument $fn
74+
Add-DocxText $w "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor" -ForeColor White -BackColor Red
75+
$w.Save()
76+
.EXAMPLE
77+
# Demonstrates adding text with paragraph style
78+
$fn = "Doc1.docx"
79+
New-Docx $fn -Empty
80+
$fn = Resolve-Path $fn
81+
$w = New-WmlDocument $fn
82+
Add-DocxText $w "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor" -Style Title
83+
$w.Save()
84+
.EXAMPLE
85+
# Demonstrates adding text with bold, italic, underline, forcolor, backcolor, style
86+
$fn = "Doc1.docx"
87+
New-Docx $fn -Empty
88+
$fn = Resolve-Path $fn
89+
$w = New-WmlDocument $fn
90+
Add-DocxText $w "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor" -Bold -Italic -Underline -ForeColor White -BackColor Red -Style Heading1
91+
$w.Save()
92+
#>
93+
94+
[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Medium')]
95+
param
96+
(
97+
[Parameter(Mandatory=$True, Position=0)]
98+
[OpenXmlPowerTools.WmlDocument]$WmlDocument,
99+
100+
[Parameter(Mandatory=$True, Position=1)]
101+
[string]$Content,
102+
103+
[Parameter(Mandatory=$False)]
104+
[Switch]
105+
[bool]$Bold,
106+
107+
[Parameter(Mandatory=$False)]
108+
[Switch]
109+
[bool]$Italic,
110+
111+
[Parameter(Mandatory=$False)]
112+
[Switch]
113+
[bool]$Underline,
114+
115+
[Parameter(Mandatory=$False)]
116+
[string]$ForeColor,
117+
118+
[Parameter(Mandatory=$False)]
119+
[string]$BackColor,
120+
121+
[Parameter(Mandatory=$False)]
122+
[string]$Style
123+
)
124+
125+
write-verbose "Appending Text to a document"
126+
127+
if ($WmlDocument -ne $null)
128+
{
129+
$newWmlDoc = [OpenXmlPowerTools.AddDocxTextHelper]::AppendParagraphToDocument(
130+
$WmlDocument,
131+
$Content,
132+
$Bold,
133+
$Italic,
134+
$Underline,
135+
$ForeColor,
136+
$BackColor,
137+
$Style)
138+
$WmlDocument.DocumentByteArray = $newWmlDoc.DocumentByteArray
139+
}
140+
}

0 commit comments

Comments
 (0)