Freigeben über


office-runtime package

Schnittstellen

OfficeRuntime.ApiInformation

Schnittstelle, die Methoden zum Überprüfen der Api-Anforderungssatzunterstützung enthält.

OfficeRuntime.Auth

Schnittstelle, die autorisierungsbezogene APIs enthält.

OfficeRuntime.AuthOptions

Stellt Optionen für die Benutzeroberfläche bereit, wenn Office ein Zugriffstoken für das Add-In von AAD v. 2.0 mit der getAccessToken -Methode abruft.

OfficeRuntime.Dialog

Objekt, das das Dialogfeld darstellt.

OfficeRuntime.DisplayWebDialogOptions

Stellt Anzeigeoptionen und Aktionen bereit, die ein Dialogfeld ausführen kann.

OfficeRuntime.Storage

Asynchroner, globaler und persistenter Schlüssel-Wert-Speicher.

Functions

OfficeRuntime.displayWebDialog(url, options)

Funktion, die ein Popup-Webdialogfeld aktiviert.

Details zur Funktion

OfficeRuntime.displayWebDialog(url, options)

Funktion, die ein Popup-Webdialogfeld aktiviert.

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

Parameter

url

string

Muss eine Zeichenfolge sein.

options
OfficeRuntime.DisplayWebDialogOptions

Optionaler Parameter. Muss vom Typ DisplayWebDialogOptions sein.

Gibt zurück

Hinweise

[ API-Satz: CustomFunctionsRuntime 1.1 ]

Beispiele

/**
 * 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}`));
    });
  });
}