views:

271

answers:

2
+2  Q: 

Merge documents

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?

+1  A: 

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 the Body-tag, describing the properties of the last section. So adding a new sectionbreak, means copying the last SectionProperties-tag to the last paragraph of the section and adding a new SectionProperties-tag under the Body-tag. I also got al lot of information from the productivity tool.

Jelle
Can you post code for that :-) Some easy to understand example :>
MadBoy
Jelle's experience mirrors mine. It's not an easy task, and it requires a lot more code than you might think. It's especially difficult to keep the styles straight since you have to prevent collisions of both the Id name.
Peter LaComb Jr.
A: 

Hi Jel,

Is there any chance you can share some code of how you did this? I am also using Alt-chunks and trying to carry over the header and footer parts.

Chris
I will try to post something this week. Kind of busy right now.
Jelle