0
votes

I have multiple <body> tags from an word document. I do this with the open xml sdk. So the new document should generated with openxml

The body's comes from

WordprocessingDocument.Open("C:\Temp\Test.docx").MainDocumentPart.Document.Body.OuterXml

I have so different body's in a list. With al different values. Changed some text in the xml. And saved them in a new list.

Now must that list in an new word document. How can i do that? I tried altChunk. But my word document is always corrupt.

Somebody that can help me?

2
I'm managing this with altChunk - post your altChunk code and we can have a look. - Shaneo

2 Answers

0
votes

You can create a WordDocument using the sdk. I think it's

WordProcessingDocument.Create("path_and_name_with_.docx").MainDocumentPart.Document.append(yourBodyList);

You could also take the resulting documents that don't work and look at it's XML using the SDK tool or just rename the doc to .zip extension and see why it doens't work.

0
votes

This function will throw exception if you are adding yourbodylist from another document without cloning. We have to use CloneNode(deep:true) for each body elements.

WordProcessingDocument.Create("path_and_name_with_.docx").MainDocumentPart.Document.append(yourBodyList); This might cause exception. Refer this post: Cannot insert the OpenXmlElement "newChild" because it is part of a tree

CloneNode(true) will create clone of the element and without any links or references to the parent. And for your multi Body problem. get the child elements of each body and add it to a new Body() element. Hope this helps!