Header and footers and merging documents


#1

Aspose.Word Folk,
I am using the standard importnode pattern of merging multiple documents into a single document. I have a problem with the source document overiding the header and footer of the destination document. I have tried using the deleteheaderfooter method which didnt work. I also tried grabbing the headerandfooter nodes that are in the destination document and putting them in every section object. This didnt work either. Is there a way I keep the header and footer information in the destination document during importation?


#2

Hi,

Thank you for considering Aspose.

If possible, please attach your documents, this would allow us to make a concrete suggestion for you.


#3

Here is the sample document. I would really appreciate it would you can rapidly find a solution to this problem.


#4

Ignore the attachment in my previous post. Attached is a zip file contain my destination document named destination.doc and the source directory contains all of my source documents.


#5

Try to use

destDoc.LastSection.AppendContent(newSection);

instead of

destDoc.Sections.Add(newSection);

Does the result suit you?


#6

AppendContent didn't work cause one of my source documents contains two columns. And when I use the AppendContent method it changes the two column section into a one column section.


#7

Sorry for the delay. I tried to call Section.ClearHeadersFooters for every imported section and it worked as expected. I’m attaching the resulting file.

This method deletes text of headers/footers of the section so MS Word treats them as linked to previous. I think this is the easiest way to avoid replacing of headers/footers. Another way is copying headers/footers where needed, and AppendContent is just an alternative.

Did you try using ClearHeadersFooters? Is this what you meant by not working method and why it failed for you then?