Word.Application class

Represents the application object.

Extends

Remarks

[ API set: WordApi 1.3 ]

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

Methods

createDocument(base64File)

Creates a new document by using an optional Base64-encoded .docx file.

newObject(context)

Create a new instance of Word.Application object

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Word.Application object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.ApplicationData) that contains shallow copies of any loaded child properties from the original object.

Property Details

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

Method Details

createDocument(base64File)

Creates a new document by using an optional Base64-encoded .docx file.

createDocument(base64File?: string): Word.DocumentCreated;

Parameters

base64File

string

Optional. The Base64-encoded .docx file. The default value is null.

Returns

Remarks

[ API set: WordApi 1.3 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/insert-external-document.yaml

// Updates the text of the current document with the text from another document passed in as a Base64-encoded string.
await Word.run(async (context) => {
  // Use the Base64-encoded string representation of the selected .docx file.
  const externalDoc = context.application.createDocument(externalDocument);
  await context.sync();

  const externalDocBody = externalDoc.body;
  externalDocBody.load("text");
  await context.sync();

  // Insert the external document's text at the beginning of the current document's body.
  const externalDocBodyText = externalDocBody.text;
  const currentDocBody = context.document.body;
  currentDocBody.insertText(externalDocBodyText, Word.InsertLocation.start);
  await context.sync();
});

newObject(context)

Create a new instance of Word.Application object

static newObject(context: OfficeExtension.ClientRequestContext): Word.Application;

Parameters

Returns

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Word.Application object is an API object, the toJSON method returns a plain JavaScript object (typed as Word.Interfaces.ApplicationData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): {
            [key: string]: string;
        };

Returns

{ [key: string]: string; }