Git Product home page Git Product logo

word-add-in-work-with-custom-xml-parts's Introduction

Word-Add-in-Work-with-custom-XML-parts

This sample writes user-specified text to a custom XML part that is bound to a content control within a Word 2013 document.

Description

The Add-ins for Office: Work with custom XML parts sample opens a Word file, CustomXMLPartSample.docx, which already contains a custom XML part that has the namespace TimeSummary. When the user enters text in the Client Name text box and chooses Update Client, the cmdUpdateClient_onClick function is executed. This function uses the getByNamespaceAsync method of the CustomXmlParts object to identify the custom XML part whose namespace is TimeSummary. The function is passed a callback function, onGotXml, which uses the getNodesAsync method of the CustomXmlPart object to get the Client node of the XML part. That function, in turn, is passed another callback function, onGotNode, which uses the setXmlAsync method of the CustomXmlNode object to set the text in the content control that is bound to the client node of the Time Summary custom XML part to the new text.

Choosing the Is Part Built In button executes the showXMLPartBuiltIn function, which uses the getByIdAsync method of the CustomXmlParts object to get the Time Summary part, and then it uses the builtIn property of the CustomXmlPart object to test whether the part is built-in or custom.

Choosing the Add Part button executes the addCustomXMLPart function, which uses the addAsync method of the CustomXmlParts object to add a new custom XML part named NewCustomXmlPart to the document. Choosing Delete Part executes the deletePart function, which uses the deleteAysnc method of the CustomXmlPart object to delete the part.

Prerequisites

This sample requires the following:

  • Word 2013.
  • Visual Studio 2012; apps for Office project template.
  • Internet Explorer 9, Internet Explorer 10, or Internet Explorer 11.
  • Basic familiarity with JavaScript and HTML.

Key components

The Add-ins for Office: Work with custom XML parts sample is created by the CustomXMLApp solution, which contains the following projects and important files:

  • The CustomXMLApp project, including the following files:
  • CustomXMLApp.xml manifest file
  • CustomXMLPartSample.docx file
  • The CustomXMLAppWeb project, including the following files:
  • Home.html file
  • Home.js file

Configure the sample

No additional configuration is necessary.

Build the sample

Choose the F5 key in Visual Studio to build and deploy the app and open it in Word 2013.

Run and test the sample

1 Open the CustomXMLApp.sln file in Visual Studio.

2 Choose the F5 key in Visual Studio to build and deploy the app.

3 In the app task pane, enter text into the Client name box, and then choose Update client name.

4 Choose Is Custom part built in? to determine whether the Time Summary part of the document is built in.

5 Choose Add CustomXML part to add a new part to the document, and choose Delete CustomXML part(s) to delete the part or parts.

You can view a list of the custom XML parts in a document by opening the XML Mapping pane in Word (Developer tab).

Troubleshooting

If the app fails to respond as described, try reloading it. (In the task pane, choose the down arrow, and then choose the Reload button.)

Change log

  • Third release.
  • GitHub release: August 2015.

Related content

word-add-in-work-with-custom-xml-parts's People

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.