sâmbătă, 5 martie 2011

Merging 2 word 2007(open xml) documents

I had to merge 2 word documents once.
They were both in word 2007(open xml) format.
I searched online everywhere for a way to merge them.
All the links were about using the altChunk element. I have a problem with that. The entire document gets put in there and that is a lot of unneeded data(like header and footer etc.).

So I did it another way:
1. cloned the second document's body
2. cloned all it's children and added them to the first document's main part


2 comentarii:

  1. Thank you so much for that code-snippet. I was looking for exactly that!
    Mike from Germany

    RăspundețiȘtergere
  2. one more thing:
    it should read:
    (with a large capital in "Paragraph"

    .InsertAfter(elem.CloneNode(true), mainPart.Document.Body.Elements().Last());

    Thanx again!

    Mike

    newsmailerformike [at] mail-4-you.de

    RăspundețiȘtergere