Excel.WorkbookRangeAreas class

Represents a collection of one or more rectangular ranges in multiple worksheets.

Extends

Remarks

[ API set: ExcelApi 1.12 ]

Properties

addresses

Returns an array of addresses in A1-style. Address values contain the worksheet name for each rectangular block of cells (e.g., "Sheet1!A1:B4, Sheet1!D1:D4"). Read-only.

areas

Returns the RangeAreasCollection object. Each RangeAreas in the collection represent one or more rectangle ranges in one worksheet.

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

ranges

Returns ranges that comprise this object in a RangeCollection object.

Methods

getRangeAreasBySheet(key)

Returns the RangeAreas object based on worksheet ID or name in the collection.

getRangeAreasOrNullObjectBySheet(key)

Returns the RangeAreas object based on worksheet name or ID in the collection. If the worksheet does not exist, then this method returns an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.WorkbookRangeAreas object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.WorkbookRangeAreasData) that contains shallow copies of any loaded child properties from the original object.

track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across .sync calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you need to add the object to the tracked object collection when the object was first created.

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call context.sync() before the memory release takes effect.

Property Details

addresses

Returns an array of addresses in A1-style. Address values contain the worksheet name for each rectangular block of cells (e.g., "Sheet1!A1:B4, Sheet1!D1:D4"). Read-only.

readonly addresses: string[];

Property Value

string[]

Remarks

[ API set: ExcelApi 1.12 ]

areas

Returns the RangeAreasCollection object. Each RangeAreas in the collection represent one or more rectangle ranges in one worksheet.

readonly areas: Excel.RangeAreasCollection;

Property Value

Remarks

[ API set: ExcelApi 1.12 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/precedents.yaml

await Excel.run(async (context) => {
  // Precedents are cells referenced by the formula in a cell.
  // A "direct precedent" is a cell directly referenced by the selected formula.
  let range = context.workbook.getActiveCell();
  let directPrecedents = range.getDirectPrecedents();
  range.load("address");
  directPrecedents.areas.load("address");
  await context.sync();

  console.log(`Direct precedent cells of ${range.address}:`);

  // Use the direct precedents API to loop through precedents of the active cell.
  for (let i = 0; i < directPrecedents.areas.items.length; i++) {
    // Highlight and console the address of each precedent cell.
    directPrecedents.areas.items[i].format.fill.color = "Yellow";
    console.log(`  ${directPrecedents.areas.items[i].address}`);
  }
  await context.sync();
});

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

ranges

Returns ranges that comprise this object in a RangeCollection object.

readonly ranges: Excel.RangeCollection;

Property Value

Remarks

[ API set: ExcelApi 1.12 ]

Method Details

getRangeAreasBySheet(key)

Returns the RangeAreas object based on worksheet ID or name in the collection.

getRangeAreasBySheet(key: string): Excel.RangeAreas;

Parameters

key

string

The name or ID of the worksheet.

Returns

Remarks

[ API set: ExcelApi 1.12 ]

getRangeAreasOrNullObjectBySheet(key)

Returns the RangeAreas object based on worksheet name or ID in the collection. If the worksheet does not exist, then this method returns an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.

getRangeAreasOrNullObjectBySheet(key: string): Excel.RangeAreas;

Parameters

key

string

The name or ID of the worksheet.

Returns

Remarks

[ API set: ExcelApi 1.12 ]

load(options)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(options?: Excel.Interfaces.WorkbookRangeAreasLoadOptions): Excel.WorkbookRangeAreas;

Parameters

options
Excel.Interfaces.WorkbookRangeAreasLoadOptions

Provides options for which properties of the object to load.

Returns

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNames?: string | string[]): Excel.WorkbookRangeAreas;

Parameters

propertyNames

string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths?: {
            select?: string;
            expand?: string;
        }): Excel.WorkbookRangeAreas;

Parameters

propertyNamesAndPaths

{ select?: string; expand?: string; }

propertyNamesAndPaths.select is a comma-delimited string that specifies the properties to load, and propertyNamesAndPaths.expand is a comma-delimited string that specifies the navigation properties to load.

Returns

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.WorkbookRangeAreas object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.WorkbookRangeAreasData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.WorkbookRangeAreasData;

Returns

track()

Track the object for automatic adjustment based on surrounding changes in the document. This call is a shorthand for context.trackedObjects.add(thisObject). If you're using this object across .sync calls and outside the sequential execution of a ".run" batch, and get an "InvalidObjectPath" error when setting a property or invoking a method on the object, you need to add the object to the tracked object collection when the object was first created.

track(): Excel.WorkbookRangeAreas;

Returns

untrack()

Release the memory associated with this object, if it has previously been tracked. This call is shorthand for context.trackedObjects.remove(thisObject). Having many tracked objects slows down the host application, so please remember to free any objects you add, once you're done using them. You will need to call context.sync() before the memory release takes effect.

untrack(): Excel.WorkbookRangeAreas;

Returns