Excel.TableRowCollection class

表示属于表的所有行的集合。Represents a collection of all the rows that are part of the table.

请注意, 与在添加新行/列之前的区域或列不同, TableRow 对象表示表行的物理位置, 而不是数据。Note that unlike Ranges or Columns, which will adjust if new rows/columns are added before them, a TableRow object represent the physical location of the table row, but not the data. 也就是说, 如果对数据进行排序或添加新行, 则表行将继续指向为其创建该索引的索引。That is, if the data is sorted or if new rows are added, a table row will continue to point at the index for which it was created.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

Extends

属性

context

与该对象关联的请求上下文。The request context associated with the object. 这会将加载项的进程连接到 Office 主机应用程序的进程。This connects the add-in's process to the Office host application's process.

count

返回表中的行数。Returns the number of rows in the table. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

items

获取此集合中已加载的子项。Gets the loaded child items in this collection.

方法

add(index, values)

向表中添加一行或多行。Adds one or more rows to the table. 返回对象是新添加的首行。The return object will be the top of the newly added row(s).

请注意, 与在添加新行/列之前的区域或列不同, TableRow 对象表示表行的物理位置, 而不是数据。Note that unlike Ranges or Columns, which will adjust if new rows/columns are added before them, a TableRow object represent the physical location of the table row, but not the data. 也就是说, 如果对数据进行排序或添加新行, 则表行将继续指向为其创建该索引的索引。That is, if the data is sorted or if new rows are added, a table row will continue to point at the index for which it was created.

[API 集: 用于添加单个行的 ExcelApi 1.1; 1.4 允许添加多个行。[ API set: ExcelApi 1.1 for adding a single row; 1.4 allows adding of multiple rows. ]

getCount()

获取表格中的行数。Gets the number of rows in the table.

[API 集: ExcelApi 1.4][ API set: ExcelApi 1.4 ]

getItemAt(index)

根据其在集合中的位置获取行。Gets a row based on its position in the collection.

请注意, 与在添加新行/列之前的区域或列不同, TableRow 对象表示表行的物理位置, 而不是数据。Note that unlike Ranges or Columns, which will adjust if new rows/columns are added before them, a TableRow object represent the physical location of the table row, but not the data. 也就是说, 如果对数据进行排序或添加新行, 则表行将继续指向为其创建该索引的索引。That is, if the data is sorted or if new rows are added, a table row will continue to point at the index for which it was created.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

load(option)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性之前,你必须调用“context.sync()”。You must call "context.sync()" before reading the properties.

load(propertyNames)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

load(option)
toJSON()

重写 JavaScript toJSON()方法, 以便在将 API 对象传递到时提供更有用的输出JSON.stringify()Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify反过来, 也会调用传递toJSON给它的对象的方法。尽管原始Excel.TableRowCollection对象是 API 对象, 但toJSON方法返回一个无格式的 JavaScript 对象 (类型为Excel.Interfaces.TableRowCollectionData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.TableRowCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.TableRowCollectionData), 其中包含集合的项中所有加载属性的浅表副本的 "items" 数组。) that contains an "items" array with shallow copies of any loaded properties from the collection's items.

属性详细信息

context

与该对象关联的请求上下文。The request context associated with the object. 这会将加载项的进程连接到 Office 主机应用程序的进程。This connects the add-in's process to the Office host application's process.

context: RequestContext;

属性值

RequestContext

count

返回表中的行数。Returns the number of rows in the table. 只读。Read-only.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

readonly count: number;

属性值

number

items

获取此集合中已加载的子项。Gets the loaded child items in this collection.

readonly items: Excel.TableRow[];

属性值

Excel.TableRow[]

方法详细信息

add(index, values)

向表中添加一行或多行。Adds one or more rows to the table. 返回对象是新添加的首行。The return object will be the top of the newly added row(s).

请注意, 与在添加新行/列之前的区域或列不同, TableRow 对象表示表行的物理位置, 而不是数据。Note that unlike Ranges or Columns, which will adjust if new rows/columns are added before them, a TableRow object represent the physical location of the table row, but not the data. 也就是说, 如果对数据进行排序或添加新行, 则表行将继续指向为其创建该索引的索引。That is, if the data is sorted or if new rows are added, a table row will continue to point at the index for which it was created.

[API 集: 用于添加单个行的 ExcelApi 1.1; 1.4 允许添加多个行。[ API set: ExcelApi 1.1 for adding a single row; 1.4 allows adding of multiple rows. ]

add(index?: number, values?: Array<Array<boolean | string | number>> | boolean | string | number): Excel.TableRow;

参数

index
number

可选。指定新行的相对位置。如果为 NULL 或 -1,将在末尾进行添加。插入的行下方的所有行都会向下移动。从零开始编制索引。Optional. Specifies the relative position of the new row. If null or -1, the addition happens at the end. Any rows below the inserted row are shifted downwards. Zero-indexed.

values
Array<Array<boolean | string | number>> | boolean | string | number

可选。Optional. 未设置格式的表行值的二维数组。A 2-dimensional array of unformatted values of the table row.

返回

示例Examples

Excel.run(function (ctx) { 
    var tables = ctx.workbook.tables;
    var values = [["Sample", "Values", "For", "New", "Row"]];
    var row = tables.getItem("Table1").rows.add(null, values);
    row.load('index');
    return ctx.sync().then(function() {
        console.log(row.index);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

getCount()

获取表格中的行数。Gets the number of rows in the table.

[API 集: ExcelApi 1.4][ API set: ExcelApi 1.4 ]

getCount(): OfficeExtension.ClientResult<number>;

返回

OfficeExtension.ClientResult<number>

getItemAt(index)

根据其在集合中的位置获取行。Gets a row based on its position in the collection.

请注意, 与在添加新行/列之前的区域或列不同, TableRow 对象表示表行的物理位置, 而不是数据。Note that unlike Ranges or Columns, which will adjust if new rows/columns are added before them, a TableRow object represent the physical location of the table row, but not the data. 也就是说, 如果对数据进行排序或添加新行, 则表行将继续指向为其创建该索引的索引。That is, if the data is sorted or if new rows are added, a table row will continue to point at the index for which it was created.

[API 集: ExcelApi 1.1][ API set: ExcelApi 1.1 ]

getItemAt(index: number): Excel.TableRow;

参数

index
number

要检索的对象的索引值。Index value of the object to be retrieved. 从零开始编制索引。Zero-indexed.

返回

示例Examples

Excel.run(function (ctx) { 
    var tablerow = ctx.workbook.tables.getItem('Table1').rows.getItemAt(0);
    tablerow.load('name');
    return ctx.sync().then(function() {
            console.log(tablerow.name);
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});

load(option)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性之前,你必须调用“context.sync()”。You must call "context.sync()" before reading the properties.

load(option?: Excel.Interfaces.TableRowCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.TableRowCollection;

参数

option
Excel.Interfaces.TableRowCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions

返回

注解

除了此签名之外, 此方法还具有以下签名:In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Excel.TableRowCollection-Where 选项是一个逗号分隔的字符串或一个字符串数组, 用于指定要加载的属性。load(option?: string | string[]): Excel.TableRowCollection - Where option is a comma-delimited string or an array of strings that specify the properties to load.

load(option?: { select?: string; expand?: string; }): Excel.TableRowCollection-Where 选项。选择是一个用逗号分隔的字符串, 用于指定要加载的属性和选项。 expand 是一个用逗号分隔的字符串, 用于指定要加载的导航属性。load(option?: { select?: string; expand?: string; }): Excel.TableRowCollection - Where option.select is a comma-delimited string that specifies the properties to load, and options.expand is a comma-delimited string that specifies the navigation properties to load.

load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.TableRowCollection-仅适用于集合类型。load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.TableRowCollection - Only available on collection types. 它类似于前面的签名。It is similar to the preceding signature. top 指定结果中可包含的集合项的最大数量。Option.top specifies the maximum number of collection items that can be included in the result. 选项。 skip 指定要跳过且不包含在结果中的项目数。Option.skip specifies the number of items that are to be skipped and not included in the result. 如果指定了 top 选项, 则在跳过指定数目的项目后将启动结果集。If option.top is specified, the result set will start after skipping the specified number of items.

load(propertyNames)

将命令加入队列以加载对象的指定属性。Queues up a command to load the specified properties of the object. 在读取属性context.sync()之前, 必须先调用。You must call context.sync() before reading the properties.

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

参数

propertyNames
string | string[]

一个以逗号分隔的字符串或字符串数组, 用于指定要加载的属性。A comma-delimited string or an array of strings that specify the properties to load.

返回

示例Examples

Excel.run(function (ctx) { 
    var tablerows = ctx.workbook.tables.getItem('Table1').rows;
    tablerows.load('items');
    return ctx.sync().then(function() {
        console.log("tablerows Count: " + tablerows.count);
        for (var i = 0; i < tablerows.items.length; i++)
        {
            console.log(tablerows.items[i].index);
        }
    });
}).catch(function(error) {
    console.log("Error: " + error);
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});
// In the example, we'll select the top 100 rows of the table.
Excel.run(function (ctx) { 
    var table = ctx.workbook.tables.getItem("Table1");
    var tableRows = table.rows.load({"select" : "index, values","top": 100, "skip": 0 })
    return ctx.sync().then(function() {
        for (var i = 0; i < tableRows.items.length; i++)
        {
            console.log(tableRows.items[i].index);
            console.log(tableRows.items[i].values);
        }
    });
}).catch(function(error) {
        console.log("Error: " + error);
        if (error instanceof OfficeExtension.Error) {
            console.log("Debug info: " + JSON.stringify(error.debugInfo));
        }
});

load(option)

load(option?: OfficeExtension.LoadOption): Excel.TableRowCollection;

参数

返回

toJSON()

重写 JavaScript toJSON()方法, 以便在将 API 对象传递到时提供更有用的输出JSON.stringify()Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify反过来, 也会调用传递toJSON给它的对象的方法。尽管原始Excel.TableRowCollection对象是 API 对象, 但toJSON方法返回一个无格式的 JavaScript 对象 (类型为Excel.Interfaces.TableRowCollectionData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.TableRowCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.TableRowCollectionData), 其中包含集合的项中所有加载属性的浅表副本的 "items" 数组。) that contains an "items" array with shallow copies of any loaded properties from the collection's items.

toJSON(): Excel.Interfaces.TableRowCollectionData;

返回