Building Word 2007 Document Templates Using Content Controls
Erika Ehrli, Lisa Wollin, Brian Jones, Microsoft Corporation
Applies to: 2007 Microsoft Office System, Microsoft Office Word 2007
Content controls are bounded and potentially labeled regions in a document that serve as containers for specific types of content. Individual content controls can contain content such as dates, lists, or paragraphs of formatted text. They enable you to create rich, structured blocks of content. Content controls enable you to create templates that insert well-defined blocks into your documents. Content controls also build on the custom XML support introduced in Microsoft Office Word 2003.
Whether you want to add or delete content controls or access and manipulate existing content controls, you can do it with code.
Adding a Content Control
Use the Add method of the ContentControls collection to add a content control to a document. The following example adds a date picker to the active document and sets the date value to the current date.
You can use the same basic construction to add any of the different types of content controls to a document.
Adding a Title to a Content Control
Use the Title property to add a title to a content control. This is text that users see, and it can help them to know what type of data to enter into the content control. The following example adds a new plain-text content control to the active document and sets the title, or display text, for the control.
Modifying Placeholder Text for a Content Control
Placeholder text is temporary text. It can be a simple one-word or two-word description (similar to the title) or it can be a more thorough description (such as numbered steps). The way that you modify placeholder text is the same regardless of the type of content control or the expected contents of the content control. The following example adds a drop-down list to the active document, sets the placeholder text for the control, and then fills the list with the names of several animals.
Content controls enable you to create templates that insert well-defined blocks into your documents. Content controls enable you to:
The easiest way to create a content control is through the user interface (UI) (although you can also create them programmatically). To create a content control through the UI, select the text that you want to turn into a content control and then choose the content control type you want from the content controls section of the Developer ribbon. This creates a content control around the selected text.
Types of Content Controls
There are seven different types of content controls that you can add to a document, each of which is represented in a new enumeration called WdContentControlType.
CalendarA date-time picker.
Building BlockEnables the user to choose from specified building blocks.
Drop-Down ListA drop-down list.
Combo BoxA combo box.
Rich TextA block of rich text.
Plain TextA block of plain text.
Video Length: 00:09:51
File Size: 13.0 MB
File Type: WMV file