Excel.WorkbookRangeAreas class

表示多个工作表中一个或多个矩形范围的集合。

扩展

属性

addresses

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

areas

返回对象 RangeAreasCollection 。 集合中的每个 RangeAreas 代表一个工作表中的一个或多个矩形范围。

context

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

ranges

返回在对象中 RangeCollection 包含此对象的范围。

方法

getRangeAreasBySheet(key)

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

getRangeAreasOrNullObjectBySheet(key)

基于集合中的工作表名称或 ID 返回 RangeAreas 对象。 如果工作表不存在,则此方法返回其 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-and-dependents.yaml

/** Highlight the direct precedents of the active cell. */
async function getDirectPrecedents() {
  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} (yellow cells):`);

    for (let i = 0; i < directPrecedents.areas.items.length; i++) {
      // Highlight and print the address of each direct 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)

基于集合中的工作表名称或 ID 返回 RangeAreas 对象。 如果工作表不存在,则此方法返回其 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;

返回