It is not essential but the code for it is below and it might save time if you have lots of templates to write. This is a set of macros that I use in the creation and testing of the template.This XML data stays in the template so it is best to use innocuous or fictitious data to preserve privacy. I used a Customer.xml file and edited it so that it was representative of data but which I could readily identify as being a sample. this is a sample of the data I will use with every field either populated or represented as empty elements and with one and only one of each node.You need to the location of this in the CustomerOrders.dotm template in its code, or keep them template and the xml in the same folder. I generate this from Access using the Northwind sample database. this is where the data will come from.You can save this in your templates folder to create new documents or you can place it in a folder so you can open it (double click) to create a new document based on it. As well as the static parts it will have Content Controls mapped to XML, and a macro to load. In this solution I will use a number of assets: They must be present in the sample otherwise, you will not be able to map them to Content Controls. In some cases, your XML source application might have mutually exclusive nodes, so you will have to fake these. The article Export XML Data from Microsoft Access – Tricks and Traps shows examples of doing this. You can fix null fields by using queries converting null fields to zero-length strings. If you export data from Microsoft Access tables, then be aware that null fields are not exported, and empty nodes are not included. The fields can be empty elements, but you must have them in the sample file. The sample must be a fully-representative example and must have ALL possible nodes and fields (elements), even if they will not necessarily be in actual XML outputs. You will need to create a sample XML file to map the structure to Content Controls it is not possible to use a proper schema for this part. It is worthwhile to progressively back it up. While you are creating a template document a misstep might break it. Reading some of the blogs and articles on other websites about mapping Content Controls to XML makes it sound straightforward. The purpose of our letter will be to advise a Northwind customer on the recent orders they have placed. This article will concentrate on using Content Controls bound to XML to generate a letter. However, there are some tricks to making nice XML from Access refer to the three-part article Export XML Data from Microsoft Access – Tricks and Traps. I am going to use the Northwind database. The first step will be creating an XML file from Access. You can, of course, use this method with any XML file. Using Content Controls is a lot easier.įor this article, I am using a single XML file created using Microsoft Access to create one document, such as a customer invoice with multiple lines or a complex report. Microsoft introduced similar XML technology in Office 2003, but unfortunately, due to a patent dispute, they were forced to delete the technology using regular Windows updates. Word mail merge does not permit data with a nested structure or when other coding methods are too tedious. Content Controls will perhaps fill a void for document generation for smaller custom applications, where specialist products like HotDocs or Windward are too expensive. But unfortunately, this article’s application did not work correctly until version Word 2019.Ĭontent Controls offer a different way of generating documents, but it is not as powerful as products like Windward and HotDocs. Microsoft has made minor improvements to Content Controls in Word 2010, but in Word 2013 they increased its utility for using this for document generation by the inclusion of a Repeating Content Control. You add an XML file to the package and then insert elements from the XML as Content Controls. Content Controls can also be bound/mapped to XML. The various templates supplied with Microsoft Word 2007, 20 include Content Controls which prompt the user to add information from the keyboard. Content Controls are a little like Word Fields. Microsoft introduced Content Controls in Word 2007. However, you should test it thoroughly before putting anything like this into a production setting. You can download the sample files at the end of the article. The same templates and code that I used for the original blog worked adequately this time. more or a variable number of child nodes.īut in Word 2019, it is back in business and appears to be working correctly. I abandoned this article in 2017 when I found that the results were not consistent when the structure of the XML file became more complicated, i.e. I wrote this to apply to Word 2013 / 2016’s Repeating Content Controls. This article shows how to create a complex structured Word 2019 Document from a template using XML as a data source.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |