Word.Application class

表示应用程序对象。

Extends

注解

[ API 集:WordApi 1.3 ]

属性

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

方法

createDocument(base64File)

使用可选的 Base64 编码.docx文件创建新文档。

newObject(context)

创建 Word 的新实例。应用程序对象

retrieveStylesFromBase64(base64File)

分析模板 Base64 文件中的样式,并将检索到的样式的 JSON 格式作为字符串返回。

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始Word。应用程序对象是一个 API 对象,toJSON该方法返回一个纯 JavaScript 对象, (类型化为Word.Interfaces.ApplicationData) ,其中包含原始对象中加载的任何子属性的浅表副本。

属性详细信息

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

方法详细信息

createDocument(base64File)

使用可选的 Base64 编码.docx文件创建新文档。

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

参数

base64File

string

可选。 Base64 编码.docx文件。 默认值为 null。

返回

注解

[ API 集:WordApi 1.3 ]

示例

// 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)

创建 Word 的新实例。应用程序对象

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

参数

返回

retrieveStylesFromBase64(base64File)

分析模板 Base64 文件中的样式,并将检索到的样式的 JSON 格式作为字符串返回。

retrieveStylesFromBase64(base64File: string): OfficeExtension.ClientResult<string>;

参数

base64File

string

必填。 模板文件。

返回

注解

[ API 集:WordApi 1.5 ]

示例

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

// Gets style info from another document passed in as a Base64-encoded string.
await Word.run(async (context) => {
  const retrievedStyles = context.application.retrieveStylesFromBase64(externalDocument);
  await context.sync();

  console.log("Styles from the other document:", retrievedStyles.value);
});

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始Word。应用程序对象是一个 API 对象,toJSON该方法返回一个纯 JavaScript 对象, (类型化为Word.Interfaces.ApplicationData) ,其中包含原始对象中加载的任何子属性的浅表副本。

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

返回

{ [key: string]: string; }