![]() You create a valid custom XML file, save the file, and then you use Visual Basic for Applications (VBA) code to add to the template document a data store that contains the information to which you want to map. The following procedure explains how to map a content control to a sample custom XML file. Save the document, naming it CustomerLetterGenerator.docm.īecause it contains VBA code, you must save the document as a macro-enabled document file (.docm).| Next, you must load a custom XML part from an XML file into the data store, by calling the Load method of the CustomXMLPart object that uses a valid path to an XML file as the parameter. Because it is empty, you cannot use it yet. This appends a new, empty data store to the document. To load a custom XML part, you must first add a new data store to a Document object by using the Add method of the CustomXMLParts collection. This creates true data/view separation between the document formatting and the custom XML data. XML mapping is a feature of Word that enables you to create a link between a document and an XML file. Set the XML mapping on the content controls. Selection.MoveDown Unit:=wdLine, Count:=1 Press ALT+F11 to open the Visual Basic editor, paste the code into the code window, click anywhere in the procedure, and then press F5 to run the code and add four content controls to your template document. You can also use the following Visual Basic for Applications (VBA) code to add content controls to the document. After you add each control, assign each one a title: Click the control in the Controls group, click Properties in the Title box, type a title for the control, as shown in the following list and then click OK. To add a content control, on the Developer tab, in the Controls group, click Plain Text Content Control.Īdd four plain-text content controls to the document. This enables you to write a simple and short application to manipulate and modify data in a document. By using XPath expressions, you can programmatically map content in an XML file to a content control. ![]() You can map these content controls to an element in an XML file. This includes text blocks, check boxes, drop-down menus, combo boxes, calendar controls, and pictures. Word offers several kinds of content controls. To create a custom document generator and define the XML mappings for each content controlĪdd plain-text content controls to the document to bind to nodes in the data store.Ĭontent controls are predefined pieces of content. Use the following general steps to create a Word document generator. The document displays the following information: The application retrieves customer data from a Microsoft SQL Server database and uses the customer letter generator to build a new document that displays customer data based on a user selection. Next, you create a document-generation web-based application that enables you to select a company name to generate a custom document. To create a Word document generator that connects an item in the data store to a Microsoft SQL Server database, you first build a template customer letter-generator document that contains content controls that map to an XML file. Business Scenario: Create a Customer Document Generator The programmatic objects that are used in this sample are as follows:ĬustomXMLPart (in the Microsoft Office system core object model)ĬustomXMLParts (in the Microsoft Office system core object model)įor more information about content controls, see Working with Content Controls. To build this application, you'll complete the following two tasks:Ĭreate a server-side web-based application that pulls data from a Microsoft SQL Server database and generates new documents based on the Word template document. This walkthrough explains how to build a new template document and how to create a server-side application that generates documents that display data that is stored in a Microsoft SQL Server database. The managed web-based application opens the template document, retrieves data from a Microsoft SQL Server database to build a new custom XML part, replaces the template document's custom XML part with the new part, and saves the template document as a new Word document. Then you can create a managed web-based application to build a new document based on the template document. Although the term template is used in this context, this document is not a Word template, but shares some characteristics of a Word template document. ![]() You can create a template document that includes a custom XML part and use content controls to bind to custom XML data by using XML mapping. Word enables you to generate documents by creating data-driven solutions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |