office-runtime package

インターフェイス

OfficeRuntime.ApiInformation

API 要件セットのサポートを確認するためのメソッドを含むインターフェイス。

OfficeRuntime.Auth

承認関連の API を含むインターフェイス。

OfficeRuntime.AuthOptions

Office が getAccessToken メソッドを使用して AAD v. 2.0 からアドインへのアクセス トークンを取得するときのユーザー エクスペリエンスのオプションを提供します。

OfficeRuntime.Dialog

ダイアログ ボックスを表すオブジェクト。

OfficeRuntime.DisplayWebDialogOptions

ダイアログ ボックスの表示オプションとアクションを提供します。

OfficeRuntime.Storage

非同期、グローバル、永続キー値ストレージ。

関数

OfficeRuntime.displayWebDialog(url, options)

ポップアップ Web ダイアログ ボックスを有効にする機能。

関数の詳細

OfficeRuntime.displayWebDialog(url, options)

ポップアップ Web ダイアログ ボックスを有効にする機能。

export function displayWebDialog(url: string, options?: DisplayWebDialogOptions): Promise<Dialog>;

パラメーター

url

string

文字列でなければなりません。

options
OfficeRuntime.DisplayWebDialogOptions

オプションのパラメーター。 型は DisplayWebDialogOptions である必要があります。

返品

注釈

API セット: CustomFunctionsRuntime 1.1

/**
 * Opens an authentication dialog from a custom function.
 * @customfunction AUTH.LOGIN
 * @returns A promise that resolves to the authentication result.
 */
async function authLogin(): Promise<string> {
  const dialogUrl = "https://your-addin-domain.com/auth-dialog.html";

  return new Promise((resolve, reject) => {
    OfficeRuntime.displayWebDialog(dialogUrl, {
      height: "50%",
      width: "40%",

      onMessage: (message: string, dialog?: OfficeRuntime.Dialog) => {
        // Handle messages sent from the dialog via window.opener.postMessage().
        const data = JSON.parse(message);

        if (data.type === "auth-success") {
          // Process the authentication token
          dialog?.close();
          resolve(`Signed in as ${data.username}`);
        } else if (data.type === "auth-error") {
          dialog?.close();
          reject(new Error(data.errorMessage));
        }
      },

      onClose: () => {
        // Handle the user closing the dialog.
        resolve("Dialog closed");
      },

      onRuntimeError: (error: Error, dialog?: OfficeRuntime.Dialog) => {
        // Handle runtime errors from the dialog.
        dialog?.close();
        reject(error);
      },
    }).catch((error) => {
      reject(new Error(`Failed to open dialog: ${error.message}`));
    });
  });
}