diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 9d5c0889..48d29bb7 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -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' diff --git a/OpenXmlPowerTools.Tests/DocumentBuilderTests.cs b/OpenXmlPowerTools.Tests/DocumentBuilderTests.cs index a0f7397d..55b69ca9 100644 --- a/OpenXmlPowerTools.Tests/DocumentBuilderTests.cs +++ b/OpenXmlPowerTools.Tests/DocumentBuilderTests.cs @@ -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() + { + 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)] diff --git a/OpenXmlPowerTools/DocumentBuilder/DocumentBuilder.cs b/OpenXmlPowerTools/DocumentBuilder/DocumentBuilder.cs index fcf61401..183f6f1e 100644 --- a/OpenXmlPowerTools/DocumentBuilder/DocumentBuilder.cs +++ b/OpenXmlPowerTools/DocumentBuilder/DocumentBuilder.cs @@ -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 { diff --git a/TestFiles/DB017-ApplyHeaderAndFooterToAllDocs-Landscape-SingleColumn.docx b/TestFiles/DB017-ApplyHeaderAndFooterToAllDocs-Landscape-SingleColumn.docx new file mode 100644 index 00000000..2f481f15 Binary files /dev/null and b/TestFiles/DB017-ApplyHeaderAndFooterToAllDocs-Landscape-SingleColumn.docx differ diff --git a/TestFiles/DB017-ApplyHeaderAndFooterToAllDocs-Portrait-TwoColumns.docx b/TestFiles/DB017-ApplyHeaderAndFooterToAllDocs-Portrait-TwoColumns.docx new file mode 100644 index 00000000..5af1995e Binary files /dev/null and b/TestFiles/DB017-ApplyHeaderAndFooterToAllDocs-Portrait-TwoColumns.docx differ