OfficeExtension.ClientObject class

Ein abstraktes Proxyobjekt, das ein Objekt in einem Office-Dokument darstellt. Sie erstellen Proxyobjekte aus dem Kontext (oder aus anderen Proxyobjekten), fügen einer Warteschlange Befehle hinzu, um auf das Objekt zu reagieren, und synchronisieren dann den Proxyobjektstatus mit dem Dokument, indem context.sync()Sie .

Eigenschaften

context

Den Anforderungskontext, der dem Objekt zugeordnet ist

isNullObject

Gibt einen booleschen Wert dafür zurück, ob das entsprechende Objekt ein Null-Objekt ist. Sie müssen vor dem Lesen der isNullObject-Eigenschaft aufrufen context.sync() .

Details zur Eigenschaft

context

Den Anforderungskontext, der dem Objekt zugeordnet ist

context: ClientRequestContext;

Eigenschaftswert

Beispiele

// *.run methods automatically create an OfficeExtension.ClientRequestContext
// object to work with the Office file.
await Excel.run(async (context: Excel.RequestContext) => {
  // `context` is the Excel-specific extension of OfficeExtension.ClientRequestContext.
  
  const workbook = context.workbook;
  // Interact with the Excel workbook...
});

isNullObject

Gibt einen booleschen Wert dafür zurück, ob das entsprechende Objekt ein Null-Objekt ist. Sie müssen vor dem Lesen der isNullObject-Eigenschaft aufrufen context.sync() .

isNullObject: boolean;

Eigenschaftswert

boolean

Beispiele

// This Word snippet sets the hyperlink URL of a selected image. 
await Word.run(async (context) => {
    const selection = context.document.getSelection();
    const firstImage = selection.inlinePictures.getFirstOrNullObject();
    await context.sync();

    // Check if an image was selected before changing its property.
    if (!firstImage.isNullObject) {
        firstImage.hyperlink = "https://www.microsoft.com";
    } else {
        console.log("No image selected");
    }

    await context.sync();
});