Document object (JavaScript API for Office v1.1)

JavaScript API for Office v1.1

An abstract class that represents the document the app is interacting with.

Last modified: June 12, 2014

Introduced in Office.js version

1.0

Updated in Office.js version

1.1

Office.context.document

Properties

Name

Description

Updates for Office.js v1.1

bindings

Gets an object that provides access to the bindings defined in the document.

Added support for content apps for Access.

customXmlParts

Gets an object that represents the custom XML parts in the document.

mode

Gets the mode the document is in.

Added support for content apps for Access.

settings

Gets an object that represents the saved custom settings of the content or task pane app for the current document.

Added support for content apps for Access.

url

Gets the URL of the document that the host application currently has open.

Added support for content apps for Access.

Methods

Name

Description

Updates for Office.js v1.1

addHandlerAsync

Adds an event handler for a Document object event.

getActiveViewAsync

Returns the current view of the presentation.

New in v1.1.

Added to support content and task pane apps for PowerPoint.

getFileAsync

Returns the entire document file in slices of up to 4194304 bytes (4MB).

Can get file as PDF in apps for PowerPoint and Word.

getFileProperties

Gets file properties of the current document.

In this release, can get only the URL of the document.

New in v1.1.

Can get the URL in apps for Excel, Word, and PowerPoint.

getSelectedDataAsync

Reads the data contained in the current selection of the document.

Added support for getting the id, title, and index for the selected range of slides in apps for PowerPoint.

goToByIdAsync

Goes to the specified object or location in the document.

New in v1.1.

Added to support navigation within the document in apps for Excel and PowerPoint.

removeHandlerAsync

Removes an event handler for a Document object event.

setSelectedDataAsync

Writes data to the current selection in the document.

Added support for setting formatting on the selected table when writing data in apps for Excel.

Events

Name

Description

SelectionChanged

Occurs when the selection in the document is changed.

You don't instantiate the Document object directly in your script. To call members of the Document object to interact with the current document or worksheet, use Office.context.document in your script.

The following example uses the getSelectedDataAsync method of the Document object to retrieve the user's current selection as text, and then display it in the app's page.


// Display the user's current selection.
function showSelection() {
    Office.context.document.getSelectedDataAsync(
        "text",                        // coercionType
        {valueFormat: "unformatted",   // valueFormat
        filterType: "all"},            // filterType
        function (result) {            // callback
            var dataValue; 
            dataValue = result.value;
            write('Selected data is: ' + dataValue);
        });
}
// Function that writes to a div with id='message' on the page.
function write(message){
    document.getElementById('message').innerText += message; 
}

App types

Content apps, Task pane apps

Supported clients

Access app for SharePoint, Excel 2013, Excel 2013 SP1, Excel 2013 RT, Excel Online, PowerPoint 2013, PowerPoint 2013 SP1, PowerPoint 2013 RT, Project 2013 SP1, Project 2013, Word 2013 SP1, Word 2013 RT, and Word 2013

Library

Office.js

Namespace

Office

Show:
© 2014 Microsoft