I’m trying to merge two docx-documents into one docx-document using OpenXML SDK 2.0. The documents should be merged without loosing their styling and custom headers and footers. I hope I can achieve this using AltChunk and a section break. But I can’t get it working.
Is it possible what I’m trying to do? Can someone give me a hint how to achieve this?
Using the ‘Open XML Productivity Tool’ I analyzed the structure of a docx-document, and concluded that merging documents with their style, headers, footers, … is not possible out of the box using
Altchunk. You can download the tool seperatly from the open xml sdk.What I’m doing now, and what is working, is copying everything manually into to document, making sure that all style-references, header-references, footer-references, … are preserved. This means that I give them a new unique id before I copy them into the document and changing all references from the old id to the new id. There is a lot of code to do this, but the tool mentioned above really helped.
Adding a section break is also quite difficult. You should know that the SectionProperties-tag describes all the properties of the section and that there can be one
SectionProperties-tag under theBody-tag, describing the properties of the last section. So adding a new sectionbreak, means copying the lastSectionProperties-tag to the last paragraph of the section and adding a newSectionProperties-tag under theBody-tag. I also got al lot of information from the productivity tool.