Skip to content

Commit 90f95d8

Browse files
authored
Merge pull request #208 from EricWhiteDev/KeepWebExtensionsParts
Add code to keep web extensions parts
2 parents b493b4b + 620a532 commit 90f95d8

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
lines changed

OpenXmlPowerTools.Tests/DocumentBuilderTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,28 @@ public void DB013b_LocalizedStyleIds_List()
702702
}
703703
}
704704

705+
[Fact]
706+
public void DB014_KeepWebExtensions()
707+
{
708+
FileInfo source = new FileInfo(Path.Combine(TestUtil.SourceDir.FullName, "DB014-WebExtensions.docx"));
709+
List<Source> sources = null;
710+
711+
sources = new List<Source>()
712+
{
713+
new Source(new WmlDocument(source.FullName)),
714+
};
715+
var processedDestDocx = new FileInfo(Path.Combine(TestUtil.TempDir.FullName, "DB014-WebExtensions.docx"));
716+
DocumentBuilder.BuildDocument(sources, processedDestDocx.FullName);
717+
Validate(processedDestDocx);
718+
719+
using (WordprocessingDocument wDoc = WordprocessingDocument.Open(processedDestDocx.FullName, false))
720+
{
721+
Assert.NotNull(wDoc.WebExTaskpanesPart);
722+
Assert.Equal(2, wDoc.WebExTaskpanesPart.Taskpanes.ChildElements.Count);
723+
Assert.Equal(2, wDoc.WebExTaskpanesPart.WebExtensionParts.Count());
724+
}
725+
}
726+
705727
private void Validate(FileInfo fi)
706728
{
707729
using (WordprocessingDocument wDoc = WordprocessingDocument.Open(fi.FullName, true))

OpenXmlPowerTools/DocumentBuilder.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,7 @@ private static void AppendDocument(WordprocessingDocument sourceDocument, Wordpr
15351535
AdjustUniqueIds(sourceDocument, newDocument, newContent);
15361536
RemoveGfxdata(newContent);
15371537
CopyCustomXml(sourceDocument, newDocument, newContent);
1538+
CopyWebExtensions(sourceDocument, newDocument);
15381539
if (insertId != null)
15391540
{
15401541
XElement insertElementToReplace = newMainXDoc
@@ -1570,6 +1571,22 @@ private static void AppendDocument(WordprocessingDocument sourceDocument, Wordpr
15701571
}
15711572
}
15721573

1574+
private static void CopyWebExtensions(WordprocessingDocument sourceDocument, WordprocessingDocument newDocument)
1575+
{
1576+
if (sourceDocument.WebExTaskpanesPart != null && newDocument.WebExTaskpanesPart == null)
1577+
{
1578+
newDocument.AddWebExTaskpanesPart();
1579+
newDocument.WebExTaskpanesPart.GetXDocument().Add(sourceDocument.WebExTaskpanesPart.GetXDocument().Root);
1580+
1581+
foreach (var sourceWebExtensionPart in sourceDocument.WebExTaskpanesPart.WebExtensionParts)
1582+
{
1583+
var newWebExtensionpart = newDocument.WebExTaskpanesPart.AddNewPart<WebExtensionPart>(
1584+
sourceDocument.WebExTaskpanesPart.GetIdOfPart(sourceWebExtensionPart));
1585+
newWebExtensionpart.GetXDocument().Add(sourceWebExtensionPart.GetXDocument().Root);
1586+
}
1587+
}
1588+
}
1589+
15731590
private static void AddToIgnorable(XElement root, string v)
15741591
{
15751592
var ignorable = root.Attribute(MC.Ignorable);

OpenXmlPowerTools/PtOpenXmlUtil.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5683,6 +5683,32 @@ public static class W16SE
56835683
public static XNamespace w16se = "http://schemas.microsoft.com/office/word/2015/wordml/symex";
56845684
}
56855685

5686+
public static class WE
5687+
{
5688+
public static readonly XNamespace we = "http://schemas.microsoft.com/office/webextensions/webextension/2010/11";
5689+
public static readonly XName alternateReferences = we + "alternateReferences";
5690+
public static readonly XName binding = we + "binding";
5691+
public static readonly XName bindings = we + "bindings";
5692+
public static readonly XName extLst = we + "extLst";
5693+
public static readonly XName properties = we + "properties";
5694+
public static readonly XName property = we + "property";
5695+
public static readonly XName reference = we + "reference";
5696+
public static readonly XName snapshot = we + "snapshot";
5697+
public static readonly XName web_extension = we + "web-extension";
5698+
public static readonly XName webextension = we + "webextension";
5699+
public static readonly XName webextensionref = we + "webextensionref";
5700+
}
5701+
5702+
public static class WETP
5703+
{
5704+
public static readonly XNamespace wetp = "http://schemas.microsoft.com/office/webextensions/taskpanes/2010/11";
5705+
public static readonly XName extLst = wetp + "extLst";
5706+
public static readonly XName taskpane = wetp + "taskpane";
5707+
public static readonly XName taskpanes = wetp + "taskpanes";
5708+
public static readonly XName web_extension_taskpanes = wetp + "web-extension-taskpanes";
5709+
public static readonly XName webextensionref = wetp + "webextensionref";
5710+
}
5711+
56865712
public static class W3DIGSIG
56875713
{
56885714
public static readonly XNamespace w3digsig =

TestFiles/DB014-WebExtensions.docx

55.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)