Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Here are the steps to merge the documents.
Step 1:
Open a new Microsoft Word 2007 document and type
A
B
C
Save the document to C:\Source.xml. Please change the “Save As Type” to “Word XML Document”.
Step 2:
Open a new Microsoft Word 2007 document and type
D
E
F
Save the document to C:\ Destination.xml. Please change the “Save As Type” to “Word XML Document”.
Step 3:
Open Source.xml in Visual Studio and add a package part to hold the content to be merged. Please note that content type is being used i.e. application/xml.
<pkg:part pkg:name="/word/embed/destination.xml" pkg:contentType="application/xml">
<pkg:xmlData>
</pkg:xmlData>
</pkg:part>
Step 4:
In Source.xml, add a relationship in document.xml.rels section.
<Relationship Id="afChunkId1" Type="https://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/embed/destination.xml"/>
Please note that value of the Target attribute should be the same as specified in step 3 for pkg:name attribute.
Step 5:
Please specify the following element in document.xml. This element should appear where you would like to see the merged data.
<w:altChunk r:id="afChunkId1" xmlns:r="https://schemas.openxmlformats.org/officeDocument/2006/relationships"/>
Step 6:
Now open destination.xml, copy everything except the processing instructions and paste in between <pkg:xmlData> element specified in step 3 in Source.xml. Please note that you can also merge the Word 2003 XML document by just copying the XML except the processing instructions and pasting in between <pkg:xmlData> element.
Step 7:
Save Source.xml and open it in Word and you will see that data is merged.
Reference Links
=========================
- Please download the ECMA-376 1st edition Part 4 from the following site. The specification for Altchunk is explained in the 4th part.
https://www.ecma-international.org/publications/standards/Ecma-376.htm - Leveraging content in other formats
https://blogs.msdn.com/brian_jones/archive/2007/01/17/leveraging-content-in-other-formats.aspx
The following link explains as how Altchunk element can be used to merge the Open XML documents using Open XML SDK.
- Creating Documents by Using the Open XML Format SDK 2.0 (Part 3 of 3)
https://msdn.microsoft.com/en-us/library/dd469465.aspx - How to Use altChunk for Document Assembly
https://blogs.msdn.com/ericwhite/archive/2008/10/27/how-to-use-altchunk-for-document-assembly.aspx - AltChunk Class (DocumentFormat.OpenXml.Wordprocessing)
https://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing.altchunk(office.14).aspx
Comments
- Anonymous
April 16, 2009
PingBack from http://stevepietrek.com/2009/04/16/links-4162009/