次の方法で共有


Office.Dialog interface

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

注釈

要件セット: DialogAPI

メソッド

addEventHandler(eventType, handler)

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

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

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

close()

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

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

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

eventTypeDialogMessageReceivedの場合はmessageプロパティとoriginプロパティを持つオブジェクト、またはeventTypeDialogEventReceivedの場合はerrorプロパティを持つオブジェクトを受け取る関数。 origin プロパティは、DialogOrigin 1.1 をサポートしていないクライアントでundefinedされることに注意してください。

戻り値

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 オブジェクトを返さないので、 await キーワードまたは then 関数で待機することはできません。 詳細については、このベスト プラクティスを参照してください。閉 じた直後に別のダイアログを開く

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