I trying to combine Word documents while keeping the header and footer (or lack thereof) intact.
For each document, I am running this code and variations of it but I cannot get the header and footer to not repeat across documents.
I would like to not repeat a documents header and/or footer across any other document.
using (var w_doc = new WordDocument(stream)
{
foreach (IWSection section in w_doc.Sections)
{
var hdr = section.HeadersFooters.FirstPageHeader;
hdr.ChildEntities.Clear();
hdr = section.HeadersFooters.EvenHeader;
hdr.ChildEntities.Clear();
hdr = section.HeadersFooters.OddHeader;
hdr.ChildEntities.Clear();
hdr = section.HeadersFooters.EvenFooter;
hdr.ChildEntities.Clear();
hdr = section.HeadersFooters.OddFooter;
hdr.ChildEntities.Clear();
hdr = section.HeadersFooters.FirstPageFooter;
hdr.ChildEntities.Clear();
hdr = section.HeadersFooters.Header;
hdr.ChildEntities.Clear();
hdr = section.HeadersFooters.Footer;
hdr.ChildEntities.Clear();
destination.Sections.Add(section.Clone());
destination.LastSection.BreakCode = section.BreakCode;
}
}