{"id":100,"date":"2011-01-26T15:05:24","date_gmt":"2011-01-26T15:05:24","guid":{"rendered":"http:\/\/www.ericwhite.com\/home2\/bm8qcmjy\/public_html\/blog\/?p=100"},"modified":"2011-01-28T14:43:34","modified_gmt":"2011-01-28T14:43:34","slug":"using-a-wordprocessingml-document-as-a-template-in-the-document-generation-process","status":"publish","type":"post","link":"https:\/\/www.ericwhite.com\/blog\/2011\/01\/26\/using-a-wordprocessingml-document-as-a-template-in-the-document-generation-process\/","title":{"rendered":"Using a WordprocessingML Document as a Template in the Document Generation Process"},"content":{"rendered":"<p>In this post, I examine the approaches for building a template document for the document generation process.<\/p>\n<p>This post is the second in a series of blog posts.\u00a0 Here is the complete list: <a href=\"https:\/\/www.ericwhite.com\/blog\/map\/generating-open-xml-wordprocessingml-documents-blog-post-series\/\">Generating Open XML WordprocessingML Documents Blog Post Series<\/a><\/p>\n<p>In my approach to document generation, a template document is a DOCX document that contains content controls that will control the document generation process.\u00a0 The document template designer can format this document as desired, and the document generation process will generate documents that have the format of the template document.<\/p>\n<p>When working with content controls, first of all, remember that you need to turn on the developer tab in the ribbon.\u00a0 Click <strong>File<\/strong> =&gt; <strong>Options<\/strong> =&gt; <strong>Customize Ribbon<\/strong>, and then turn on the developer tab:<\/p>\n<div class=\"mceTemp\">\n<div id=\"attachment_102\" style=\"width: 535px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.ericwhite.com\/blog\/wp-content\/uploads\/2011\/01\/Gen011.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-102\" class=\"size-full wp-image-102\" title=\"Turning on the Developer Tab\" src=\"https:\/\/www.ericwhite.com\/blog\/wp-content\/uploads\/2011\/01\/Gen011.jpg\" alt=\"Turning on the Developer Tab\" width=\"525\" height=\"355\" \/><\/a><p id=\"caption-attachment-102\" class=\"wp-caption-text\">Turning on the Developer Tab<\/p><\/div>\n<\/div>\n<p>Another point that will make it easier to work with content controls is to turn on design mode.\u00a0 If design mode is turned off (which is the default), content controls have a square boxed appearance with a tab at the top that contains the title of the content control:<\/p>\n<div id=\"attachment_103\" style=\"width: 575px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.ericwhite.com\/blog\/wp-content\/uploads\/2011\/01\/Gen02.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-103\" class=\"size-full wp-image-103\" title=\"Content Control - not in Design Mode\" src=\"https:\/\/www.ericwhite.com\/blog\/wp-content\/uploads\/2011\/01\/Gen02.jpg\" alt=\"Content Control - not in Design Mode\" width=\"565\" height=\"224\" srcset=\"https:\/\/www.ericwhite.com\/blog\/wp-content\/uploads\/2011\/01\/Gen02.jpg 565w, https:\/\/www.ericwhite.com\/blog\/wp-content\/uploads\/2011\/01\/Gen02-300x118.jpg 300w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/a><p id=\"caption-attachment-103\" class=\"wp-caption-text\">Content Control - not in Design Mode<\/p><\/div>\n<p>This is not a problem, except that if the focus is not in a content control, there is no visual indication that the content control is there.\u00a0 Instead, turn on design mode:<\/p>\n<div id=\"attachment_104\" style=\"width: 566px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.ericwhite.com\/blog\/wp-content\/uploads\/2011\/01\/Gen03.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-104\" class=\"size-full wp-image-104\" title=\"Turning on design mode\" src=\"https:\/\/www.ericwhite.com\/blog\/wp-content\/uploads\/2011\/01\/Gen03.jpg\" alt=\"Turning on design mode\" width=\"556\" height=\"78\" \/><\/a><p id=\"caption-attachment-104\" class=\"wp-caption-text\">Turning on design mode<\/p><\/div>\n<p>With design mode turned on, content controls have blue tags that indicate the beginning and end of the location of a content control.\u00a0 With design mode turned on, a template document will look something like the following:<\/p>\n<div id=\"attachment_116\" style=\"width: 589px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.ericwhite.com\/blog\/wp-content\/uploads\/2011\/01\/Gen041.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-116\" class=\"size-full wp-image-116\" title=\"Sample template document with content controls\" src=\"https:\/\/www.ericwhite.com\/blog\/wp-content\/uploads\/2011\/01\/Gen041.jpg\" alt=\"Sample template document with content controls\" width=\"579\" height=\"644\" \/><\/a><p id=\"caption-attachment-116\" class=\"wp-caption-text\">Sample template document with content controls<\/p><\/div>\n<p>In this document, plain text content controls contain a LINQ query that returns a single value.\u00a0 Formatting is easy \u2013 the value returned by the query takes on the formatting of the containing run or paragraph.<\/p>\n<p>In this document,\u00a0the rich text\u00a0content control\u00a0with Table as its title\u00a0contains a LINQ query that returns a collection of anonymous types.\u00a0 The results of the query will be inserted into the document as a WordprocesssingML table.\u00a0 The inserted table will have the formatting of the empty table that is inserted into the rich text content control.<\/p>\n<h2><strong>Other uses of the word \u2018Template\u2019 in Microsoft Office<\/strong><\/h2>\n<p>One minor issue around the idea of creating a template WordprocessingML document is that the term \u2018template\u2019 is overloaded.\u00a0 Microsoft Word has the notion of \u2018Document Templates\u2019, which are saved with the dotx extension.\u00a0 These are WordprocessingML documents with one special characteristic \u2013 when the user opens one of these documents, the user cannot directly save back to the dotx file \u2013 the user must instead supply a new filename, and Word will append docx as the extension.<\/p>\n<p>In addition, related to dotx document templates are &#8216;document template projects&#8217; in Visual Studio 2010 (and 2008).\u00a0 These are template-based document-level projects (see <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/zcfbd2sk.aspx\">Architecture of Document-Level Customizations<\/a>) that consist of managed code that is attached to a document template instead of a document.\u00a0 The user opens the template, uses the managed customization to do whatever it does, and then saves as a docx document.\u00a0 The docx document can have a managed customization, or it can be stripped of the customization, leaving a plain old docx.<\/p>\n<p>For this document generation project, we don\u2019t need to use either of these facilities.\u00a0 Instead, the template document that the designer creates is, as far as Word is concerned, an ordinary word-processing document.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I examine the approaches for building a template document for the document generation process.  In my approach to document generation, a template document is a DOCX document that contains content controls that will control the document generation process.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_s2mail":"","footnotes":""},"categories":[7,3,5],"tags":[],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-document-generation-series","category-open-xml","category-wordprocessingml"],"_links":{"self":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/comments?post=100"}],"version-history":[{"count":20,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/100\/revisions"}],"predecessor-version":[{"id":141,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/100\/revisions\/141"}],"wp:attachment":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/media?parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/categories?post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/tags?post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}