![]() stand up object that reads the Word doc package String docTemplatePath = docOutputPath = copy of template so that we don't overwrite itįile.Copy(docTemplatePath, docOutputPath) Ĭonsole.WriteLine("Created copy of template. get path to template and instance output Next I have all the code which makes a copy of my template, loads up the Word document, removes the existing XML part, and adds a new one which has been populated with the values I want within the Content Controls.Ĭonsole.WriteLine("Starting up Word template updater. I then added the following “using” statements to my console class. Mine was found here: C:\Program Files\OpenXMLSDK\\lib\. After you’ve done that, create a new VS.NET Console project and add a reference to DocumentFormat.OpenXML. If you haven’t done so already, download and install the Open XML Format SDK 1.0 from Microsoft. For this blog post, I’ll resort to a Console application which reads the template and emits the resulting Word document to my Desktop. zip, we’ll see a new folder called CustomXml that has our XML definition in there.įor my real prototype I built a WCF service that created the Word documents out of the templates and loaded them into SharePoint. Now, if we once again peek inside our Word doc by changing it’s extension to. Go ahead and save the settings and close the tool. When all four are complete, the XPath column in the Content Controls should be populated. Switch to the Bind view and you should see a tree structure.Ĭlick each node, and then drag it to the corresponding Content Control. The values I put inside each XML node are the values that the Word document will display in each content control. After choosing to create a new part, I switched to the Edit view so that I could easily hand craft an XML data structure.įor a more complex structure, I could have also uploaded an existing XML structure. The astute among you may now guess that I will click the “Click here to create a new one.” I have smart readers. On the right hand side of the Word 2007 Content Control Toolkit you’ll see a window that tells us that there are currently no custom XML parts in the document. What we need to do next is define a Custom XML Part for this Word document, and tie the individual XML nodes to each Content Control. You’ll notice that the XPath column is empty. After browsing to our Word document, we see our friendly-named Content Controls in the list. First, download the Word 2007 Content Control Toolkit from CodePlex. ![]() I looked a few options for manipulating the underlying XML content and finally ended up on the easiest way to update my Content Controls with data from outside. If you change the extension of our just-saved Word doc from. As you probably know by now, the Office 2007 document formats are really just zip files. For each content control on the page, select it and choose the Properties button on the ribbon so that you can provide the control with a friendly name.Īt this point, I have four Content Controls in my document and each has a friendly title. ![]() The text of each control should indicate the type of content that goes there. Now I’m going to sprinkle a few Text Content Controls throughout my document. Don’t see the Developer tab? Go here to see how to enable it. Next, I switch to the Developer tab to find the Content Controls I want to inject into my document. ![]() Because I’m not feeling particular frisky today, I will fill this document with random text using the ever-useful “=rand(9)” command to make Word put 9 random paragraphs into my document. So, I figured that I’d demonstrate the prototype solution that I built.įirst, we need a Word 2007 document. I found a few articles and blog posts that explained some of the steps, but didn’t seem to find a single source of the whole end to end process. I first looked at a few commercial options, and then got some recommendations from Microsoft to look deeper into the Open XML SDK and leverage the native XML formats of the Office 2007 document types. Today this is a manual process where the user opens up a Microsoft Word template and retypes the data points stored in their primary application. I recently had a client at work interested in populating contracts out of the information stored in their task tracking tool.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |