Manually create a Word document by binding a custom xml document to a template Word document

This post describes how you can create a Microsoft Office Word (2007/2010/2013) document by merging a Word template and a custom xml document.


Note: This post uses Microsoft Office Word 2013, but the same applies to Microsoft Office Word 2007 and 2010.



Open Microsoft Office Word 2013 open the developer tab on the ribbon




If the developer tab is not visible, go to File > Options



Go to Customize Ribbon > Enable "Developer" tab



First insert some text, a table and an image to give the template some body.

Now insert a Plain Text Content Control



Click on Properties and enter as:

Title: "CustomerName"

Tag: "CustomerName"



Save the document to "C:\Temp\CustomerInfo.docx" and close Microsoft Office Word



Rename the file to "C:\Temp\"




Extract the file to "C:\Temp\CustomerInfo"




Add the folder "C:\Temp\CustomerInfo\customXml"




Create the files item1.xml and itemProps1.xml and the folder _rels in the folder "C:\Temp\CustomerInfo\customXml"





<name>Customer 1</name>






<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<ds:datastoreItem ds:itemID="{8f93798d-1506-45f2-811e-70f72165a32d}" xmlns:ds="" />

The itemID is just a GUID.



You can create a new GUID with Microsoft Visual Studio:




Create a file item1.xml.rels in the folder "C:\Temp\CustomerInfo\customXml\_rels"

<?xml version="1.0" encoding="utf-8"?>

<Relationships xmlns="">

<Relationship Type="" Target="/customXml/itemProps1.xml" Id="Rb8d5386a2f8640f88dad1eff30868bcf" />


The Id is just a GUID without "-".

Edit the file "C:\Temp\CustomerInfo\word\_rels\document.xml.rels"

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<Relationships xmlns="">

<Relationship Id="rId3" Type="" Target="webSettings.xml"/>

<Relationship Id="rId7" Type="" Target="theme/theme1.xml"/>

<Relationship Id="rId2" Type="" Target="settings.xml"/>

<Relationship Id="rId1" Type="" Target="styles.xml"/>

<Relationship Id="rId6" Type="" Target="glossary/document.xml"/>

<Relationship Id="rId5" Type="" Target="fontTable.xml"/><Relationship Id="rId4" Type="" Target="media/image1.jpeg"/>

<Relationship Type="" Target="../customXml/item1.xml" Id="Rdfc14bfb0c244ab3" />


The ID is a GUID without "-".


Edit the file "C:\Temp\CustomerInfo\word\document.xml"

Search for "CustomerName" in the file.


Add <w:dataBinding w:xpath="/root/customer[1]/name[1]" w:storeItemID="{8f93798d-1506-45f2-811e-70f72165a32d}" />

just after the <w:sdtPr> containing the CustomerName content control.





Edit the file "C:\Temp\CustomerInfo\[Content_Types].xml"


Now when you zip the contents of the folder "C:\Temp\CustomerInfo" and rename the zip to CustomerInfo2.docx, the CustomerName content control should be automatically filled with the text "Customer 1" from the item1.xml file.

When zipping make sure, you zip the contents of the folder en not the folder itself:



These manual steps can be automated by using the tool: (Word Content Control Toolkit)

This tool was created for Office 2007, but can be used for Office 2010 and Office 2013.

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *