Skip to content

Commit

Permalink
Fix - merging multiple documents with and without headers and footers
Browse files Browse the repository at this point in the history
  • Loading branch information
stesee authored Jul 6, 2023
2 parents 9cb0b61 + 56d0d4a commit 8501bf6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
pull-requests: write

steps:
- uses: actions/stale@v7
- uses: actions/stale@v8
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Stale issue message'
Expand Down
17 changes: 17 additions & 0 deletions OpenXmlPowerTools.Tests/DocumentBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,23 @@ public void DB0016_DocDefaultStyles()
Assert.Single(styles);
}

[Fact]
public void DB017_ApplyHeaderAndFooterToAllDocs()
{
var sourceDir = new DirectoryInfo("../../../../TestFiles/");
var source1 = new FileInfo(Path.Combine(sourceDir.FullName, "DB017-ApplyHeaderAndFooterToAllDocs-Portrait-TwoColumns.docx"));
var source2 = new FileInfo(Path.Combine(sourceDir.FullName, "DB017-ApplyHeaderAndFooterToAllDocs-Landscape-SingleColumn.docx"));

var sources = new List<Source>()
{
new Source(new WmlDocument(source1.FullName)){KeepSections = true},
new Source(new WmlDocument(source2.FullName)){KeepSections = true, DiscardHeadersAndFootersInKeptSections = true},
};

var processedDestDocx = new FileInfo(Path.Combine(Path.Combine(TestUtil.TempDir.FullName), "DB017-ApplyHeaderAndFooterToAllDocs.docx"));
DocumentBuilder.BuildDocument(sources, processedDestDocx.FullName);
}

[Theory]
[InlineData("DB100-00010", "DB/GlossaryDocuments/CellLevelContentControl-built.docx", "DB/GlossaryDocuments/BaseDocument.docx,0,4", "DB/GlossaryDocuments/CellLevelContentControl.docx", "DB/GlossaryDocuments/BaseDocument.docx,4", null, null, null)]
[InlineData("DB100-00020", "DB/GlossaryDocuments/InlineContentControl-built.docx", "DB/GlossaryDocuments/BaseDocument.docx,0,4", "DB/GlossaryDocuments/InlineContentControl.docx", "DB/GlossaryDocuments/BaseDocument.docx,4", null, null, null)]
Expand Down
7 changes: 5 additions & 2 deletions OpenXmlPowerTools/DocumentBuilder/DocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,8 +1169,11 @@ private static void CopyOrCacheHeaderOrFooter(WordprocessingDocument doc, Cached
var referenceElement = FindReference(sect, referenceXName, type);
if (referenceElement == null)
{
var cachedPartRid = cachedHeaderFooter.FirstOrDefault(z => z.Ref == referenceXName && z.Type == type).CachedPartRid;
AddReferenceToExistingHeaderOrFooter(sect, cachedPartRid, referenceXName, type);
var cachedPartRid = cachedHeaderFooter.FirstOrDefault(z => z.Ref == referenceXName && z.Type == type)?.CachedPartRid;
if (cachedPartRid != null)
{
AddReferenceToExistingHeaderOrFooter(sect, cachedPartRid, referenceXName, type);
}
}
else
{
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 8501bf6

Please sign in to comment.