OfficeExtension.ClientObject class

An abstract proxy object that represents an object in an Office document. You create proxy objects from the context (or from other proxy objects), add commands to a queue to act on the object, and then synchronize the proxy object state with the document by calling context.sync().

Properties

context

The request context associated with the object

isNullObject

Returns a boolean value for whether the corresponding object is a null object. You must call context.sync() before reading the isNullObject property.

Property Details

context

The request context associated with the object

context: ClientRequestContext;

Property Value

Examples

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

Returns a boolean value for whether the corresponding object is a null object. You must call context.sync() before reading the isNullObject property.

isNullObject: boolean;

Property Value

boolean

Examples

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