![]() This walkthrough demonstrates how to create a document-level customization that uses content controls to create structured and reusable content in a Microsoft Office Word template. Applies to: The information in this topic applies to document-level projects for Word. For more information, see. Word enables you to create a collection of reusable document parts, named building blocks. This walkthrough shows how to create two tables as building blocks. Each table contains several content controls that can hold different types of content, such as plain text or dates. One of the tables contains information about an employee, and the other table contains customer feedback. After you create a document from the template, you can add either of the tables to the document by using several objects, which display the available building blocks in the template. This walkthrough illustrates the following tasks: • Creating tables that contain content controls in a Word template at design time. Is it possible to lock parts of a Word template, and make some of it work via a menu or wizard? My company would like to take our existing Word templates and (1) lock. Hi, I'm creating a word template and on a certain text paragraph I want the user to be able to edit the text, make it italic or bold, but not let the user change the font size. Is this possible? ![]() ![]() ![]() • Populating a combo box content control and a drop-down list content control programmatically. • Preventing users from editing a specified table. • Adding tables to the building block collection of a template. • Creating a content control that displays the available building blocks in the template. Note Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see. Create a table that contains four different types of content controls where the user can enter information about an employee. To create the employee table • In the Word template that is hosted in the Visual Studio designer, on the Ribbon, click the Insert tab. • In the Tables group, click Table, and insert a table with 2 columns and 4 rows. • Type text in the first column so that it resembles the following column: Employee Name Hire Date Title Picture • Click in the first cell in the second column (next to Employee Name). • On the Ribbon, click the Developer tab. Note If the Developer tab is not visible, you must first show it. For more information, see. • In the Controls group, click the Text button to add a to the first cell. • Click the second cell in the second column (next to Hire Date). • In the Controls group, click the Date Picker button to add a to the second cell. • Click the third cell in the second column (next to Title). • In the Controls group, click the Combo Box button to add a to the third cell. • Click the last cell in the second column (next to Picture). • In the Controls group, click the Picture Content Control button to add a to the last cell. Create a table that contains three different types of content controls where the user can enter customer feedback information. To create the customer feedback table • In the Word template, click in the line after the employee table that you added earlier, and press ENTER to add a new paragraph. • On the Ribbon, click the Insert tab. • In the Tables group, click Table, and insert a table with 2 columns and 3 rows. • Type text in the first column so that it resembles the following column: Customer Name Satisfaction Rating Comments • Click in the first cell of the second column (next to Customer Name). • On the Ribbon, click the Developer tab. • In the Controls group, click the Text button to add a to the first cell. • Click in the second cell of the second column (next to Satisfaction Rating). • In the Controls group, click the Drop-Down List button to add a to the second cell. • Click in the last cell of the second column (next to Comments). • In the Controls group, click the Rich Text button to add a to the last cell. You can initialize content controls at design time by using the Properties window in Visual Studio. You can also initialize them at run time, which enables you to set their initial states dynamically. For this walkthrough, use code to populate the entries in the and at run time so that you can see how these objects work. To modify the UI of the content controls programmatically • In Solution Explorer, right-click ThisDocument.cs or ThisDocument.vb, and then click View Code. • Add the following code to the ThisDocument class. This code declares several objects that you will use later in this walkthrough. ComboBoxContentControl1.PlaceholderText = 'Choose a title, or enter your own'; comboBoxContentControl1.DropDownListEntries.Add( 'Engineer', 'Engineer', 0); comboBoxContentControl1.DropDownListEntries.Add( 'Designer', 'Designer', 1); comboBoxContentControl1.DropDownListEntries.Add( 'Manager', 'Manager', 2); dropDownListContentControl1.PlaceholderText = 'Choose a rating (1 lowest, 3 highest)'; dropDownListContentControl1.DropDownListEntries.Add( '1', '1', 0); dropDownListContentControl1.DropDownListEntries.Add( '2', '2', 1); dropDownListContentControl1.DropDownListEntries.Add( '3', '3', 2). Use the object that you declared earlier to protect the employee table. After protecting the table, users can still edit the content controls in the table. However, they cannot edit text in the first column or modify the table in other ways, such as adding or deleting rows and columns. For more information about how to use a to protect a part of a document, see. To prevent users from editing the employee table • Add the following code to the ThisDocument_Startup method of the ThisDocument class, after the code that you added in the previous step. This code prevents users from editing the employee table by putting the table inside the object that you declared earlier. Add the tables to a collection of document building blocks in the template so that users can insert the tables that you have created into the document. For more information about document building blocks, see. To add the tables to the building blocks in the template • Add the following code to the ThisDocument_Startup method of the ThisDocument class, after the code that you added in the previous step. This code adds new building blocks that contain the tables to the Microsoft.Office.Interop.Word.BuildingBlockEntries collection, which contains all the reusable building blocks in the template. The new building blocks are defined in a new category named Employee and Customer Information and are assigned the building block type Microsoft.Office.Interop.Word.WdBuildingBlockTypes.wdTypeCustom1. Create a content control that provides access to the building blocks (that is, the tables) that you created earlier. Users can click this control to add the tables to the document. To create a content control that displays the building blocks • Add the following code to the ThisDocument_Startup method of the ThisDocument class, after the code that you added in the previous step. This code initializes the object that you declared earlier. The displays all building blocks that are defined in the category Employee and Customer Information and that have the building block type Microsoft.Office.Interop.Word.WdBuildingBlockTypes.wdTypeCustom1. Users can click the building block gallery controls in the document to insert the employee table or the customer feedback table. Users can type or select responses in the content controls in both of the tables. Users can modify other parts of the customer feedback table, but they should not be able to modify other parts of the employee table. To test the employee table • Press F5 to run the project. • Click Choose your first building block to display the first building block gallery content control. • Click the drop-down arrow next to the Custom Gallery 1 heading in the control, and select Employee Table. • Click in the cell to the right of the Employee Name cell and type a name. Verify that you can add only text to this cell. The allows users to add only text, not other types of content such as art or a table. • Click in the cell to the right of the Hire Date cell and select a date in the date picker. • Click in the cell to the right of the Title cell and select one of the job titles in the combo box. Optionally, type the name of a job title that is not in the list. This is possible because the enables users to select from a list of entries or to type their own entries. • Click the icon in the cell to the right of the Picture cell and browse to an image to display it. • Try to add rows or columns to the table, and try to delete rows and columns from the table. Verify that you cannot modify the table. The prevents you from making any modifications. To test the customer feedback table • Click Choose your second building block to display the second building block gallery content control. • Click the drop-down arrow next to the Custom Gallery 1 heading in the control, and select Customer Table. • Click in the cell to the right of the Customer Name cell and type a name. • Click in the cell to the right of the Satisfaction Rating cell and select one of the available options. Verify that you cannot type your own entry. The allows users only to select from a list of entries. • Click in the cell to the right of the Comments cell and type some comments. Optionally, add some content other than text, such as art or an embedded table. This is possible because the enables users to add content other than text. • Verify that you can add rows or columns to the table, and that you can delete rows and columns from the table. This is possible because you have not protected the table by putting it in a. • Close the template.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2018
Categories |