There are two simple ways to get the Office Open XML markup you need. You can insert Excel charts as live charts in Word documents, which also means you can use them in your add-in for Word.Īs you can see by the preceding examples, you can use Office Open XML coercion to insert essentially any type of content that a user can insert into their own document. Office offers a wide array of SmartArt diagram layouts (and you can use Office Open XML to create your own). Use built-in or custom table styles just as easily as using a paragraph style for text. Include text formatting, borders, shading, cell sizing, or any table formatting you need.įigure 9. Insert built-in or custom drawing shapes, with or without text and formatting effects. Text effects are available in Word for text inside a text box (as shown here) or for regular body text. Use content controls with your add-in to add content at a specified (bound) location rather than at the selection.įigure 6. An image formatted using picture styles and effectsĪdding high quality formatting and effects to your images requires much less markup than you might expect. Use the same method for inserting any Office-supported image format.įigure 4. Use a style to automatically coordinate the look of text you insert with the user's document. Use direct formatting to specify exactly what the text will look like regardless of existing formatting in the user's document. Throughout this article, the terms content types and rich content refer to the types of rich content you can insert into a Word document. To begin, take a look at some of the content types you can insert using Office Open XML coercion. Download the companion code sampleĭownload the code sample Load and write Open XML in your Word add-in, which contains the Office Open XML markup and Office.js code required for inserting any of the following examples into Word. For more information about Office Open XML, including the complete language reference documentation, see the See also section. However, currently, you can coerce content as Office Open XML only in Office Add-ins created for Word. Office Open XML is also the language behind PowerPoint and Excel (and, as of Office 2013, Visio) documents. Determining the Office Open XML markup you need to get it done is easier than you might think. dotx) are written, you can insert virtually any type of content that a user can add to a Word document, with virtually any type of formatting the user can apply. Because Office Open XML is the language in which Word documents (such as.
Depending on your scenario, there can be drawbacks to HTML coercion, such as limitations in the formatting and positioning options available to your content. If APIs aren't yet available, you can use HTML for inserting some types of rich content, such as pictures. You can try this and other snippets in the Script Lab add-in on Word! To learn more about Script Lab, see Explore Office JavaScript API using Script Lab. For an example, see the Insert formatted text code snippet. Start with the APIs available through the WordApi requirement sets to see if they provide what you need.
So what are your options when you need to add rich content to a document, such as images, formatted tables, charts, or even just formatted text? These are called coercion types, and they include plain text, tables, HTML, and Office Open XML. If you're building Office Add-ins to run in Word, you might already know that the Office JavaScript API (Office.js) offers several formats for reading and writing document content. Provided by: Stephanie Krieger, Microsoft Corporation | Juan Balmori Labra, Microsoft Corporation