Table of contents
- Summary
- Prerequisites
- Key components of the sample
- Description of the code
- Build and debug
- Troubleshooting
- Questions and comments
- Additional resources
##Summary This sample shows how to add and bind to a named rich text content control in Word, and how to insert content at the bound location.
This sample requires the following:
- Word 2013 or Word 2016.
- Visual Studio 2013 (Update 5) or Visual Studio 2015, with Microsoft Office Developer Tools.
- Any browser that supports ECMAScript 5.1, HTML5, and CSS3, such as Internet Explorer 9, Chrome 13, Firefox 5, Safari 5.0.6, or a later version of these browsers.
The sample solution contains the following key files:
PopulateBindings project
- PopulateBindings.xml: The manifest file for the Word add-in.
PopulateBindingsWeb project
- App/Home/Home.html. The HTML user interface that is displayed in the task pane. It contains one button to insert a rich text content control and bind to it, and two buttons to populate the binding (with two interchangeable content options).
- App/Home/Home.js. Logic that runs when the add-in is loaded.
- Snippets_BindAndPopulate folder. Contains three XML files that define the markup for the rich text content control and for the two content samples.
##Description of the code The sample demonstrates how to:
- Use the setSelectedDataAsync method with the ooxml coercion type to add a rich text content control.
- Use the addFromNamedItemAsync method to bind to the control.
- Use the setDataAsync method with the ooxml coercion type to populate the binding.
The add-in initializes in a blank Word document. The following screenshot shows the initial view of the task pane add-in.
Bindings can greatly expand the options for Word add-ins. Use bindings to add content at a specified location in the document, not just at the user's active selection point. In Word add-ins, rich text controls are the only type of content control you can bind to. Note that the control placeholder content must include at least one complete paragraph in order to enable you to populate the binding with multi-paragraph content. The file ContentControl.xml in the Snippets_BindAndPopulate folder in this solution shows how to structure your content control for successful binding. To learn more about working with bindings in Word add-ins, see Creating Better Word Add-ins with Office Open XML.
-
In Visual Studio, press F5 to build and deploy the solution. Word opens and displays the task pane add-in. You can optionally add content in the document.
-
In the add-in, click Add and Bind Control. The placeholder text for the control appears in the document.
-
Click one of the Insert buttons to populate the binding initially, and the other to replace the contents of the binding with new content.
- If the add-in does not appear in the task pane of the presentation, Choose Insert > My Add-ins > Populate Bindings.
- If you have any trouble running this sample, please log an issue.
- Questions about Office Add-ins development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with [office-addins].
- Office Add-ins documentation on MSDN
- Standard ECMA-376: Office Open XML File Formats
- Creating Better Word Add-ins with Office Open XML
- More Add-in samples
Copyright (c) 2015 Microsoft. All rights reserved.