Excel.PivotTableCollection class

表示属于工作簿或工作表的所有 PivotTable 对象的集合。Represents a collection of all the PivotTables that are part of the workbook or worksheet.

[API 集: ExcelApi 1.3][ API set: ExcelApi 1.3 ]

Extends

属性

context

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

items

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

方法

add(name, source, destination)

基于指定的数据源添加数据透视表,并将其插入到目标区域的左上单元格。Add a Pivottable based on the specified source data and insert it at the top left cell of the destination range.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

getCount()

获取集合中的数据透视表的数量。Gets the number of pivot tables in the collection.

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

getItem(name)

按名称获取 PivotTable 对象。Gets a PivotTable by name.

[API 集: ExcelApi 1.3][ API set: ExcelApi 1.3 ]

getItemOrNullObject(name)

按 PivotTable 对象的名称获取此对象。Gets a PivotTable by name. 如果没有 PivotTable 对象,将返回 NULL 对象。If the PivotTable does not exist, will return a null object.

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

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)
refreshAll()

刷新集合中的所有数据透视表。Refreshes all the pivot tables in the collection.

[API 集: ExcelApi 1.3][ API set: ExcelApi 1.3 ]

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.PivotTableCollection对象是 API 对象, 但toJSON方法返回一个无格式的 JavaScript 对象 (类型为Excel.Interfaces.PivotTableCollectionData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.PivotTableCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.PivotTableCollectionData), 其中包含集合的项中所有加载属性的浅表副本的 "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

items

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

readonly items: Excel.PivotTable[];

属性值

Excel.PivotTable[]

方法详细信息

add(name, source, destination)

基于指定的数据源添加数据透视表,并将其插入到目标区域的左上单元格。Add a Pivottable based on the specified source data and insert it at the top left cell of the destination range.

[API 集: ExcelApi 1.8][ API set: ExcelApi 1.8 ]

add(name: string, source: Range | string | Table, destination: Range | string): Excel.PivotTable;

参数

name
string

新数据透视表的名称。The name of the new PivotTable.

source
Range | string | Table

新数据透视表的源数据, 可以是区域 (或包含工作表名称的字符串地址) 或表。The source data for the new PivotTable, this can either be a range (or string address including the worksheet name) or a table.

destination
Range | string

数据透视表目标区域(工作表中用于放置所生成的报表的区域)左上角的单元格。The cell in the upper-left corner of the PivotTable report's destination range (the range on the worksheet where the resulting report will be placed).

返回

返回新插入的数据透视表。Returns the newly inserted PivotTable.

示例Examples

await Excel.run(async (context) => {
    const rangeToAnalyze = context.workbook.worksheets.getItem("Data").getRange("A1:E21");
    const rangeToPlacePivot = context.workbook.worksheets.getItem("Pivot").getRange("A2");
    context.workbook.worksheets.getItem("Pivot").pivotTables.add("Farm Sales", rangeToAnalyze, rangeToPlacePivot);

    await context.sync();
});

getCount()

获取集合中的数据透视表的数量。Gets the number of pivot tables in the collection.

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

getCount(): OfficeExtension.ClientResult<number>;

返回

OfficeExtension.ClientResult<number>

getItem(name)

按名称获取 PivotTable 对象。Gets a PivotTable by name.

[API 集: ExcelApi 1.3][ API set: ExcelApi 1.3 ]

getItem(name: string): Excel.PivotTable;

参数

name
string

要检索的数据透视表的名称。Name of the PivotTable to be retrieved.

返回

getItemOrNullObject(name)

按 PivotTable 对象的名称获取此对象。Gets a PivotTable by name. 如果没有 PivotTable 对象,将返回 NULL 对象。If the PivotTable does not exist, will return a null object.

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

getItemOrNullObject(name: string): Excel.PivotTable;

参数

name
string

要检索的数据透视表的名称。Name of the PivotTable to be retrieved.

返回

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.PivotTableCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.PivotTableCollection;

参数

option
Excel.Interfaces.PivotTableCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions

返回

注解

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

load(option?: string | string[]): Excel.PivotTableCollection-Where 选项是一个逗号分隔的字符串或一个字符串数组, 用于指定要加载的属性。load(option?: string | string[]): Excel.PivotTableCollection - 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.PivotTableCollection-Where 选项。选择是一个用逗号分隔的字符串, 用于指定要加载的属性和选项。 expand 是一个用逗号分隔的字符串, 用于指定要加载的导航属性。load(option?: { select?: string; expand?: string; }): Excel.PivotTableCollection - 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.PivotTableCollection-仅适用于集合类型。load(option?: { select?: string; expand?: string; top?: number; skip?: number }): Excel.PivotTableCollection - 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.PivotTableCollection;

参数

propertyNames
string | string[]

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

返回

load(option)

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

参数

返回

refreshAll()

刷新集合中的所有数据透视表。Refreshes all the pivot tables in the collection.

[API 集: ExcelApi 1.3][ API set: ExcelApi 1.3 ]

refreshAll(): void;

返回

void

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.PivotTableCollection对象是 API 对象, 但toJSON方法返回一个无格式的 JavaScript 对象 (类型为Excel.Interfaces.PivotTableCollectionData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.PivotTableCollection object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.PivotTableCollectionData), 其中包含集合的项中所有加载属性的浅表副本的 "items" 数组。) that contains an "items" array with shallow copies of any loaded properties from the collection's items.

toJSON(): Excel.Interfaces.PivotTableCollectionData;

返回