Excel.WorkbookRangeAreas class

表示多个工作表中一个或多个矩形区域的集合。

Extends

注解

[ API 集:ExcelApi 1.12 ]

属性

addresses

返回 A1 样式的地址数组。 地址值包含每个矩形单元格块的工作表名称, (例如“Sheet1!A1:B4,Sheet1!D1:D4“) 。 此为只读属性。

areas

返回 RangeAreasCollection 对象。 RangeAreas集合中的每个表示一个工作表中的一个或多个矩形区域。

context

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

ranges

返回在 对象中 RangeCollection 构成此对象的区域。

方法

getRangeAreasBySheet(key)

RangeAreas基于集合中的工作表 ID 或名称返回 对象。

getRangeAreasOrNullObjectBySheet(key)

RangeAreas根据集合中的工作表名称或 ID 返回 对象。 如果工作表不存在,则此方法返回一个 对象,其 isNullObject 属性设置为 true。 有关详细信息,请参阅 *OrNullObject 方法和属性

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始 Excel.WorkbookRangeAreas 对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.WorkbookRangeAreasData) ,该对象包含从原始对象加载的任何子属性的浅表副本。

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果跨 .sync 调用和在“.run”批处理的顺序执行之外使用此对象,并在设置属性或调用对象方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将该对象添加到跟踪的对象集合。

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存释放生效之前,需要调用 。context.sync()

属性详细信息

addresses

返回 A1 样式的地址数组。 地址值包含每个矩形单元格块的工作表名称, (例如“Sheet1!A1:B4,Sheet1!D1:D4“) 。 此为只读属性。

readonly addresses: string[];

属性值

string[]

注解

[ API 集:ExcelApi 1.12 ]

areas

返回 RangeAreasCollection 对象。 RangeAreas集合中的每个表示一个工作表中的一个或多个矩形区域。

readonly areas: Excel.RangeAreasCollection;

属性值

注解

[ API 集:ExcelApi 1.12 ]

示例

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

与 对象关联的请求上下文。 这会将加载项的进程连接到 Office 主机应用程序的进程。

context: RequestContext;

属性值

ranges

返回在 对象中 RangeCollection 构成此对象的区域。

readonly ranges: Excel.RangeCollection;

属性值

注解

[ API 集:ExcelApi 1.12 ]

方法详细信息

getRangeAreasBySheet(key)

RangeAreas基于集合中的工作表 ID 或名称返回 对象。

getRangeAreasBySheet(key: string): Excel.RangeAreas;

参数

key

string

工作表的名称或 ID。

返回

注解

[ API 集:ExcelApi 1.12 ]

getRangeAreasOrNullObjectBySheet(key)

RangeAreas根据集合中的工作表名称或 ID 返回 对象。 如果工作表不存在,则此方法返回一个 对象,其 isNullObject 属性设置为 true。 有关详细信息,请参阅 *OrNullObject 方法和属性

getRangeAreasOrNullObjectBySheet(key: string): Excel.RangeAreas;

参数

key

string

工作表的名称或 ID。

返回

注解

[ API 集:ExcelApi 1.12 ]

load(options)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

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

参数

options
Excel.Interfaces.WorkbookRangeAreasLoadOptions

提供要加载对象的属性的选项。

返回

load(propertyNames)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

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

参数

propertyNames

string | string[]

逗号分隔的字符串或指定要加载的属性的字符串数组。

返回

load(propertyNamesAndPaths)

将命令加入队列以加载对象的指定属性。 阅读属性前必须先调用 context.sync()

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

参数

propertyNamesAndPaths

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

propertyNamesAndPaths.select 是一个逗号分隔的字符串,指定要加载的属性,是 propertyNamesAndPaths.expand 一个逗号分隔的字符串,指定要加载的导航属性。

返回

toJSON()

重写 JavaScript toJSON() 方法,以便在将 API 对象传递给 JSON.stringify()时提供更有用的输出。 JSON.stringify (,反过来又调用toJSON传递给它的 对象的 方法。) 而原始 Excel.WorkbookRangeAreas 对象是 API 对象,toJSON但该方法返回一个纯 JavaScript 对象, (类型为 Excel.Interfaces.WorkbookRangeAreasData) ,该对象包含从原始对象加载的任何子属性的浅表副本。

toJSON(): Excel.Interfaces.WorkbookRangeAreasData;

返回

track()

根据文档中的相应更改来跟踪对象,以便进行自动调整。 此调用是 context.trackedObjects.add (thisObject) 的简写。 如果跨 .sync 调用和在“.run”批处理的顺序执行之外使用此对象,并在设置属性或调用对象方法时收到“InvalidObjectPath”错误,则需要在首次创建对象时将该对象添加到跟踪的对象集合。

track(): Excel.WorkbookRangeAreas;

返回

untrack()

释放与此对象关联的内存(如果先前已跟踪过)。 此调用是 context.trackedObjects.remove (thisObject) 的简写。 拥有许多跟踪对象会降低主机应用程序的速度,因此请在使用完毕后释放所添加的任何对象。 在内存释放生效之前,需要调用 。context.sync()

untrack(): Excel.WorkbookRangeAreas;

返回