Office.Dialog interface

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

注釈

要件セット: DialogApi

使用元

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

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();
            // Do something to process the message.
        });
    }
);

// 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();
            // Do something to process the message.
        });
    }
);

メソッド

addEventHandler(eventType, handler)

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

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

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

close()

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

このメソッドは非同期です。 コールバック パラメーターを取らず、Promise オブジェクトを返さないので、await キーワード (keyword) 関数または 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 の場合は messageorigin プロパティを持つオブジェクト、または error プロパティを持つオブジェクト (eventTypeDialogEventReceived の場合) のいずれかを受け入れる関数。 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 キーワード (keyword) 関数または 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 (最小要件セット: Mailbox 1.9)、PowerPoint、Word

要件セット:

従来の Outlook on Mac ではメールボックス 1.9 はサポートされませんが、DialogApi 1.2 はサポートされます。

// The following example shows how to send information about the current active worksheet to the dialog.
await Excel.run(async (context) => {
    const worksheet = context.workbook.worksheets.getActiveWorksheet();
    worksheet.load();
    await context.sync();
    worksheetPropertiesChanged(worksheet);
});

...

function worksheetPropertiesChanged(currentWorksheet) {
    const messageToDialog = JSON.stringify(currentWorksheet);
    dialog.messageChild(messageToDialog);
}

sendMessage(name)

内部でのみ使用します。 コードを呼び込まないでください。

sendMessage(name: string): void;

パラメーター

name

string

返品

void