Share via


Word.Application class

アプリケーション オブジェクトを表します。

Extends

注釈

[ API セット: WordApi 1.3 ]

プロパティ

context

オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。

メソッド

createDocument(base64File)

オプションの Base64 でエンコードされた.docx ファイルを使用して、新しいドキュメントを作成します。

newObject(context)

Wordの新しいインスタンスを作成します。アプリケーション オブジェクト

retrieveStylesFromBase64(base64File)

テンプレート Base64 ファイルからスタイルを解析し、取得したスタイルの JSON 形式を文字列として返します。

toJSON()

API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを 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()

API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON() メソッドを JSON.stringify()オーバーライドします。 (JSON.stringifyさらに、渡される オブジェクトの メソッドを呼び出toJSONします)。一方、元のWord。アプリケーション オブジェクトは API オブジェクトです。メソッドは、元のtoJSONオブジェクトから読み込まれた子プロパティの浅いコピーを含むプレーンな JavaScript オブジェクト (としてWord.Interfaces.ApplicationData型指定) を返します。

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

戻り値

{ [key: string]: string; }