OfficeDev/Word-Add-in-JavaScript-AddPopulateBindings

Name: Word-Add-in-JavaScript-AddPopulateBindings

Owner: Office Developer

Description: Shows how to add and bind to a named rich text content control in Word, and how to insert content at the bound location.

Created: 2015-08-19 02:35:17.0

Updated: 2016-11-28 12:04:08.0

Pushed: 2018-01-31 20:25:22.0

Homepage: null

Size: 1127

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Word Add-in: Add, bind to, and populate a rich text content control

Table of contents

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.

Prerequisites

This sample requires the following:

Key components of the sample

The sample solution contains the following key files:

PopulateBindings project

PopulateBindingsWeb project

Description of the code

The sample demonstrates how to:

The add-in initializes in a blank Word document. The following screenshot shows the initial view of the task pane add-in.

The initial view of the add-in with its three buttons

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.

Build and debug
  1. In Visual Studio, press F5 to build and deploy the solution. You can optionally add content in the document.

  2. In the Home ribbon, click Open in the Populate Bindings group.

  3. In the add-in, click Add and Bind Control. The placeholder text for the control appears in the document.

    Document showing the control's placeholder text

  4. Click one of the Insert buttons to populate the binding initially, and the other to replace the contents of the binding with new content.

    Document showing new image and formatted text content in the control

Troubleshooting

Questions and comments

Additional resources
Copyright

Copyright (c) 2015 Microsoft. All rights reserved.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.