Office.Dialog interface

が呼び出されたときに UI.displayDialogAsync 返される オブジェクト。 イベント ハンドラーを登録し、ダイアログを閉じるためのメソッドを公開します。

注釈

要件セット: DialogAPI

メソッド

addEventHandler(eventType, handler)

イベント ハンドラーを登録します。 サポートされているイベントは次の 2 つです。

  • DialogMessageReceived。 ダイアログ ボックスがメッセージを親に送信すると発生します。

  • DialogEventReceived。 ダイアログ ボックスが閉じられたとき、またはアンロードされたときに発生します。

close()

対応するダイアログ ボックスを閉じるために親ページから呼び出されます。

このメソッドは非同期です。 コールバック パラメーターは受け取らず、Promise オブジェクトも返されないため、キーワード (keyword)またはthen関数でawait待機することはできません。 詳細については、このベスト プラクティスを参照してください。閉 じた直後に別のダイアログを開く

messageChild(message, messageOptions)

作業ウィンドウや UI レス関数ファイルなどのホスト ページから、ページから開かれたダイアログにメッセージを配信します。

sendMessage(name)

内部使用のみ。 コードでを呼び出さないでください。

メソッドの詳細

addEventHandler(eventType, handler)

イベント ハンドラーを登録します。 サポートされているイベントは次の 2 つです。

  • DialogMessageReceived。 ダイアログ ボックスがメッセージを親に送信すると発生します。

  • DialogEventReceived。 ダイアログ ボックスが閉じられたとき、またはアンロードされたときに発生します。

addEventHandler(eventType: Office.EventType, handler: (args: {message: string, origin: string | undefined} | {error: number}) => void): void;

パラメーター

eventType
Office.EventType

DialogMessageReceived または DialogEventReceived である必要があります。

handler

(args: {message: string, origin: string | undefined} | {error: number}) => void

origin プロパティを持つmessageオブジェクト (が の場合eventType)DialogMessageReceived または プロパティを持つerrorオブジェクト (が の場合eventType) DialogEventReceivedを受け取る関数。 プロパティoriginは、undefinedDialogOrigin 1.1 をサポートしていないクライアント上にあります

戻り値

void

// The following example shows how to open a dialog with a specified size. It also shows
// how to register a function to handle the message when Office.UI.messageParent() is called
// in the dialog and how to use that handler to close the dialog. The implementation of the processMessage() function is omitted.

Office.context.ui.displayDialogAsync("https://www.contoso.com/myDialog.html", { height: 30, width: 20 },
    (asyncResult) => {
        const dialog = asyncResult.value;
        dialog.addEventHandler(Office.EventType.DialogMessageReceived, (arg) => {
            dialog.close();
            processMessage(arg);
        });
    }
);

// The following example does the same thing in TypeScript.

Office.context.ui.displayDialogAsync("https://www.contoso.com/myDialog.html", { height: 30, width: 20 },
    (asyncResult: Office.AsyncResult) => {
        const dialog: Office.Dialog = asyncResult.value;
        dialog.addEventHandler(Office.EventType.DialogMessageReceived, (arg: string) => {
            dialog.close();
            processMessage(arg);
        });
    }
);

close()

対応するダイアログ ボックスを閉じるために親ページから呼び出されます。

このメソッドは非同期です。 コールバック パラメーターは受け取らず、Promise オブジェクトも返されないため、キーワード (keyword)またはthen関数でawait待機することはできません。 詳細については、このベスト プラクティスを参照してください。閉 じた直後に別のダイアログを開く

close(): void;

戻り値

void

// The following example shows how to open a dialog with a specified size. It also shows
// how to register a function to handle the message when Office.UI.messageParent() is called
// in the dialog and how to use that handler to close the dialog. The implementation of the processMessage() function is omitted.

Office.context.ui.displayDialogAsync("https://www.contoso.com/myDialog.html", { height: 30, width: 20 },
    (asyncResult) => {
        const dialog = asyncResult.value;
        dialog.addEventHandler(Office.EventType.DialogMessageReceived, (arg) => {
            dialog.close();
            processMessage(arg);
        });
    }
);

// The following example does the same thing in TypeScript.

Office.context.ui.displayDialogAsync("https://www.contoso.com/myDialog.html", { height: 30, width: 20 },
    (asyncResult: Office.AsyncResult) => {
        const dialog: Office.Dialog = asyncResult.value;
        dialog.addEventHandler(Office.EventType.DialogMessageReceived, (arg: string) => {
            dialog.close();
            processMessage(arg);
        });
    }
);

messageChild(message, messageOptions)

作業ウィンドウや UI レス関数ファイルなどのホスト ページから、ページから開かれたダイアログにメッセージを配信します。

messageChild(message: string, messageOptions?: DialogMessageOptions): void;

パラメーター

message

string

ダイアログに配信するホスト ページからのメッセージを受け入れます。 JSON や XML など、文字列にシリアル化できるものは何でも送信できます。

messageOptions
Office.DialogMessageOptions

オプション。 メッセージを送信する方法のオプションを提供します。

戻り値

void

注釈

アプリケーション: Excel、Outlook (最小要件セット: メールボックス 1.9)、PowerPoint、Word

要件セット:

sendMessage(name)

内部使用のみ。 コードでを呼び出さないでください。

sendMessage(name: string): void;

パラメーター

name

string

戻り値

void