Freigeben über


Word.Application class

Stellt das Anwendungsobjekt dar.

Extends

Hinweise

[ API-Satz: WordApi 1.3 ]

Eigenschaften

context

Der Anforderungskontext, der dem -Objekt zugeordnet ist. Dadurch wird der Prozess des Add-Ins mit dem Prozess der Office-Hostanwendung verbunden.

Methoden

createDocument(base64File)

Erstellt ein neues Dokument mithilfe einer optionalen Base64-codierten .docx Datei.

newObject(context)

Erstellen Sie eine neue instance Word. Application-Objekt

retrieveStylesFromBase64(base64File)

Analysieren Sie Formatvorlagen aus einer Base64-Vorlagendatei, und geben Sie das JSON-Format der abgerufenen Formatvorlagen als Zeichenfolge zurück.

toJSON()

Überschreibt die JavaScript-Methode toJSON() , um eine nützlichere Ausgabe bereitzustellen, wenn ein API-Objekt an JSON.stringify()übergeben wird. (JSON.stringifyruft wiederum die toJSON -Methode des Objekts auf, das an das Objekt übergeben wird.) Die ursprüngliche Word. Das Anwendungsobjekt ist ein API-Objekt. Die toJSON Methode gibt ein einfaches JavaScript-Objekt (typisiert als Word.Interfaces.ApplicationData) zurück, das flache Kopien aller geladenen untergeordneten Eigenschaften aus dem ursprünglichen Objekt enthält.

Details zur Eigenschaft

context

Der Anforderungskontext, der dem -Objekt zugeordnet ist. Dadurch wird der Prozess des Add-Ins mit dem Prozess der Office-Hostanwendung verbunden.

context: RequestContext;

Eigenschaftswert

Details zur Methode

createDocument(base64File)

Erstellt ein neues Dokument mithilfe einer optionalen Base64-codierten .docx Datei.

createDocument(base64File?: string): Word.DocumentCreated;

Parameter

base64File

string

Optional. Die Base64-codierte .docx-Datei. Der Standardwert ist null.

Gibt zurück

Hinweise

[ API-Satz: WordApi 1.3 ]

Beispiele

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/insert-external-document.yaml

// Updates the text of the current document with the text from another document passed in as a Base64-encoded string.
await Word.run(async (context) => {
  // Use the Base64-encoded string representation of the selected .docx file.
  const externalDoc = context.application.createDocument(externalDocument);
  await context.sync();

  const externalDocBody = externalDoc.body;
  externalDocBody.load("text");
  await context.sync();

  // Insert the external document's text at the beginning of the current document's body.
  const externalDocBodyText = externalDocBody.text;
  const currentDocBody = context.document.body;
  currentDocBody.insertText(externalDocBodyText, Word.InsertLocation.start);
  await context.sync();
});

newObject(context)

Erstellen Sie eine neue instance Word. Application-Objekt

static newObject(context: OfficeExtension.ClientRequestContext): Word.Application;

Parameter

Gibt zurück

retrieveStylesFromBase64(base64File)

Analysieren Sie Formatvorlagen aus einer Base64-Vorlagendatei, und geben Sie das JSON-Format der abgerufenen Formatvorlagen als Zeichenfolge zurück.

retrieveStylesFromBase64(base64File: string): OfficeExtension.ClientResult<string>;

Parameter

base64File

string

Erforderlich. Die Vorlagendatei.

Gibt zurück

Hinweise

[ API-Satz: WordApi 1.5 ]

Beispiele

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/word/50-document/get-external-styles.yaml

// Gets style info from another document passed in as a Base64-encoded string.
await Word.run(async (context) => {
  const retrievedStyles = context.application.retrieveStylesFromBase64(externalDocument);
  await context.sync();

  console.log("Styles from the other document:", retrievedStyles.value);
});

toJSON()

Überschreibt die JavaScript-Methode toJSON() , um eine nützlichere Ausgabe bereitzustellen, wenn ein API-Objekt an JSON.stringify()übergeben wird. (JSON.stringifyruft wiederum die toJSON -Methode des Objekts auf, das an das Objekt übergeben wird.) Die ursprüngliche Word. Das Anwendungsobjekt ist ein API-Objekt. Die toJSON Methode gibt ein einfaches JavaScript-Objekt (typisiert als Word.Interfaces.ApplicationData) zurück, das flache Kopien aller geladenen untergeordneten Eigenschaften aus dem ursprünglichen Objekt enthält.

toJSON(): {
            [key: string]: string;
        };

Gibt zurück

{ [key: string]: string; }