Excel.PivotLayout class

表示数据透视表的可视化布局。Represents the visual layout of the PivotTable.

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

Extends

属性

autoFormat

指定在刷新或移动域时是否自动设置格式设置的格式Specifies whether formatting will be automatically formatted when it’s refreshed or when fields are moved

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

context

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

enableFieldList

指定字段列表是否可以显示在 UI 中。Specifies whether the field list can be shown in the UI.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

layoutType

此属性指示数据透视表上的所有字段的 PivotLayoutType。This property indicates the PivotLayoutType of all fields on the PivotTable. 如果字段状态不同,则为 null。If fields have different states, this will be null.

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

preserveFormatting

指定当通过透视、排序或更改页字段项等操作刷新或重新计算报表时, 是否保留格式设置。Specifies whether formatting is preserved when the report is refreshed or recalculated by operations such as pivoting, sorting, or changing page field items.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

showColumnGrandTotals

指定数据透视表报表是否显示列总计。Specifies whether the PivotTable report shows grand totals for columns.

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

showRowGrandTotals

指定数据透视表报表是否显示行总计。Specifies whether the PivotTable report shows grand totals for rows.

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

subtotalLocation

此属性指示数据透视表上的所有字段的 SubtotalLocationType。This property indicates the SubtotalLocationType of all fields on the PivotTable. 如果字段状态不同,则为 null。If fields have different states, this will be null.

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

方法

getCell(dataHierarchy, rowItems, columnItems)

基于数据层次结构以及其各自的层次结构的行和列项, 获取数据透视表中的唯一单元格。Gets a unique cell in the PivotTable based on a data hierarchy and the row and column items of their respective hierarchies. 返回的单元格是给定的行和包含给定层次结构中的数据的列的交集。The returned cell is the intersection of the given row and column that contains the data from the given hierarchy. 此方法是对特定单元格调用 getPivotItems 和 getDataHierarchy 的反函数。This method is the inverse of calling getPivotItems and getDataHierarchy on a particular cell.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

getColumnLabelRange()

返回数据透视表列标签所在位置的区域。Returns the range where the PivotTable's column labels reside.

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

getDataBodyRange()

返回数据透视表数据值所在位置的区域。Returns the range where the PivotTable's data values reside.

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

getDataHierarchy(cell)

获取 DataHierarchy,它用于计算数据透视表中指定区域内的值。Gets the DataHierarchy that is used to calculate the value in a specified range within the PivotTable.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

getFilterAxisRange()

返回数据透视表筛选区的区域。Returns the range of the PivotTable's filter area.

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

getPivotItems(axis, cell)

从构成数据透视表中指定区域内的值的轴获取 PivotItems。Gets the PivotItems from an axis that make up the value in a specified range within the PivotTable.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

getPivotItems(axisString, cell)

从构成数据透视表中指定区域内的值的轴获取 PivotItems。Gets the PivotItems from an axis that make up the value in a specified range within the PivotTable.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

getRange()

返回存在数据透视表的区域,不包括筛选区。Returns the range the PivotTable exists on, excluding the filter area.

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

getRowLabelRange()

返回数据透视表行标签所在位置的区域。Returns the range where the PivotTable's row labels reside.

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

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

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

set(properties, options)

同时设置一个对象的多个属性。Sets multiple properties of an object at the same time. 您可以传递具有相应属性的纯对象或相同类型的其他 API 对象。You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties)

基于现有加载的对象同时设置该对象的多个属性。Sets multiple properties on the object at the same time, based on an existing loaded object.

setAutoSortOnCell(cell, sortBy)

将数据透视表设置为使用指定的单元格自动进行排序, 以自动选择所有必需的条件和上下文。Sets the PivotTable to automatically sort using the specified cell to automatically select all necessary criteria and context. 这与从 UI 应用自动排序的行为相同。This behaves identically to applying an autosort from the UI.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

setAutoSortOnCell(cell, sortByString)

将数据透视表设置为使用指定的单元格自动进行排序, 以自动选择所有必需的条件和上下文。Sets the PivotTable to automatically sort using the specified cell to automatically select all necessary criteria and context. 这与从 UI 应用自动排序的行为相同。This behaves identically to applying an autosort from the UI.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

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给它的对象的方法。尽管原始 PivotLayout 对象是 API 对象, 但toJSON方法返回一个无格式的 JavaScript 对象 (类型为Excel.Interfaces.PivotLayoutData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.PivotLayout object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.PivotLayoutData), 其中包含原始对象中所有已加载的子属性的浅表副本。) that contains shallow copies of any loaded child properties from the original object.

属性详细信息

autoFormat

指定在刷新或移动域时是否自动设置格式设置的格式Specifies whether formatting will be automatically formatted when it’s refreshed or when fields are moved

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

autoFormat: boolean;

属性值

boolean

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

enableFieldList

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

指定字段列表是否可以显示在 UI 中。Specifies whether the field list can be shown in the UI.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

enableFieldList: boolean;

属性值

boolean

layoutType

此属性指示数据透视表上的所有字段的 PivotLayoutType。This property indicates the PivotLayoutType of all fields on the PivotTable. 如果字段状态不同,则为 null。If fields have different states, this will be null.

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

layoutType: Excel.PivotLayoutType | "Compact" | "Tabular" | "Outline";

属性值

Excel.PivotLayoutType | "Compact" | "Tabular" | "Outline"

preserveFormatting

指定当通过透视、排序或更改页字段项等操作刷新或重新计算报表时, 是否保留格式设置。Specifies whether formatting is preserved when the report is refreshed or recalculated by operations such as pivoting, sorting, or changing page field items.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

preserveFormatting: boolean;

属性值

boolean

showColumnGrandTotals

指定数据透视表报表是否显示列总计。Specifies whether the PivotTable report shows grand totals for columns.

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

showColumnGrandTotals: boolean;

属性值

boolean

showRowGrandTotals

指定数据透视表报表是否显示行总计。Specifies whether the PivotTable report shows grand totals for rows.

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

showRowGrandTotals: boolean;

属性值

boolean

subtotalLocation

此属性指示数据透视表上的所有字段的 SubtotalLocationType。This property indicates the SubtotalLocationType of all fields on the PivotTable. 如果字段状态不同,则为 null。If fields have different states, this will be null.

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

subtotalLocation: Excel.SubtotalLocationType | "AtTop" | "AtBottom" | "Off";

属性值

Excel.SubtotalLocationType | "AtTop" | "AtBottom" | "Off"

方法详细信息

getCell(dataHierarchy, rowItems, columnItems)

备注

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

基于数据层次结构以及其各自的层次结构的行和列项, 获取数据透视表中的唯一单元格。Gets a unique cell in the PivotTable based on a data hierarchy and the row and column items of their respective hierarchies. 返回的单元格是给定的行和包含给定层次结构中的数据的列的交集。The returned cell is the intersection of the given row and column that contains the data from the given hierarchy. 此方法是对特定单元格调用 getPivotItems 和 getDataHierarchy 的反函数。This method is the inverse of calling getPivotItems and getDataHierarchy on a particular cell.

[API 集: EXCELAPI BETA (仅限预览)][ API set: ExcelApi BETA (PREVIEW ONLY) ]

getCell(dataHierarchy: DataPivotHierarchy | string, rowItems: Array<PivotItem | string>, columnItems: Array<PivotItem | string>): Excel.Range;

参数

dataHierarchy
DataPivotHierarchy | string

提供要查找的数据项的 dataHierarchy。The dataHierarchy that provides the data item to find.

rowItems
Array<PivotItem | string>

行轴中的 PivotItems, 这些行轴构成要查找的值。The PivotItems from the row axis that make up the value to find.

columnItems
Array<PivotItem | string>

由列坐标轴构成的 PivotItems, 这些值构成要查找的值。The PivotItems from the column axis that make up the value to find.

返回

指定包含指定值的单个单元格的范围。A range specifying a single cell that contains the value specified.

getColumnLabelRange()

返回数据透视表列标签所在位置的区域。Returns the range where the PivotTable's column labels reside.

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

getColumnLabelRange(): Excel.Range;

返回

getDataBodyRange()

返回数据透视表数据值所在位置的区域。Returns the range where the PivotTable's data values reside.

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

getDataBodyRange(): Excel.Range;

返回

示例Examples

await Excel.run(async (context) => {
    const pivotTable = context.workbook.worksheets.getActiveWorksheet().pivotTables.getItem("Farm Sales");

    // the layout controls the ranges used by the PivotTable
    const range = pivotTable.layout.getDataBodyRange();

    // get all the data hierarchy totals
    const grandTotalRange = range.getLastRow();
    grandTotalRange.load("address");
    await context.sync();
    
    // use the wholesale and farm sale totals to make a final sum
    const masterTotalRange = context.workbook.worksheets.getActiveWorksheet().getRange("B27:C27");
    masterTotalRange.formulas = [["All Crates", "=SUM(" + grandTotalRange.address + ")"]];
    await context.sync();
});

getDataHierarchy(cell)

获取 DataHierarchy,它用于计算数据透视表中指定区域内的值。Gets the DataHierarchy that is used to calculate the value in a specified range within the PivotTable.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

getDataHierarchy(cell: Range | string): Excel.DataPivotHierarchy;

参数

cell
Range | string

数据透视表数据正文中的单个单元格。A single cell within the PivotTable data body.

返回

用于计算指定单元格中的值的 DataPivotHierarchy 对象。The DataPivotHierarchy object used to calculate the value in the specified cell.

getFilterAxisRange()

返回数据透视表筛选区的区域。Returns the range of the PivotTable's filter area.

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

getFilterAxisRange(): Excel.Range;

返回

getPivotItems(axis, cell)

从构成数据透视表中指定区域内的值的轴获取 PivotItems。Gets the PivotItems from an axis that make up the value in a specified range within the PivotTable.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

getPivotItems(axis: Excel.PivotAxis, cell: Range | string): OfficeExtension.ClientResult<Excel.PivotItem[]>;

参数

axis
Excel.PivotAxis

要从其获取 PivotItems 的轴。The axis from which to get the PivotItems. 必须是 "行" 或 "列"。Must be either "row" or "column."

cell
Range | string

数据透视表的数据正文中的单个单元格。A single cell within the PivotTable's data body.

返回

OfficeExtension.ClientResult<Excel.PivotItem[]>

用于计算指定行中的值的 PivotItems 的集合。A collection of PivotItems that are used to calculate the values in the specified row.

getPivotItems(axisString, cell)

从构成数据透视表中指定区域内的值的轴获取 PivotItems。Gets the PivotItems from an axis that make up the value in a specified range within the PivotTable.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

getPivotItems(axisString: "Unknown" | "Row" | "Column" | "Data" | "Filter", cell: Range | string): OfficeExtension.ClientResult<Excel.PivotItem[]>;

参数

axisString
"Unknown" | "Row" | "Column" | "Data" | "Filter"

要从其获取 PivotItems 的轴。The axis from which to get the PivotItems. 必须是 "行" 或 "列"。Must be either "row" or "column."

cell
Range | string

数据透视表的数据正文中的单个单元格。A single cell within the PivotTable's data body.

返回

OfficeExtension.ClientResult<Excel.PivotItem[]>

用于计算指定行中的值的 PivotItems 的集合。A collection of PivotItems that are used to calculate the values in the specified row.

getRange()

返回存在数据透视表的区域,不包括筛选区。Returns the range the PivotTable exists on, excluding the filter area.

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

getRange(): Excel.Range;

返回

getRowLabelRange()

返回数据透视表行标签所在位置的区域。Returns the range where the PivotTable's row labels reside.

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

getRowLabelRange(): Excel.Range;

返回

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.PivotLayoutLoadOptions): Excel.PivotLayout;

参数

返回

注解

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

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

参数

propertyNames
string | string[]

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

返回

load(propertyNamesAndPaths)

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

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

参数

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

其中, propertyNamesAndPaths 是用逗号分隔的字符串, 用于指定要加载的属性和 propertyNamesAndPaths。扩展是一个用逗号分隔的字符串, 用于指定要加载的导航属性。Where 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.

返回

set(properties, options)

同时设置一个对象的多个属性。Sets multiple properties of an object at the same time. 您可以传递具有相应属性的纯对象或相同类型的其他 API 对象。You can pass either a plain object with the appropriate properties, or another API object of the same type.

set(properties: Interfaces.PivotLayoutUpdateData, options?: OfficeExtension.UpdateOptions): void;

参数

properties
Interfaces.PivotLayoutUpdateData

一个 JavaScript 对象, 其属性的结构 isomorphically 为在其上调用方法的对象的属性。A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

提供一个选项, 以在 properties 对象尝试设置任何只读属性时禁止显示错误。Provides an option to suppress errors if the properties object tries to set any read-only properties.

返回

void

注解

此方法具有以下附加签名:This method has the following additional signature:

set(properties: Excel.PivotLayout): void

set(properties)

基于现有加载的对象同时设置该对象的多个属性。Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Excel.PivotLayout): void;

参数

properties
Excel.PivotLayout

返回

void

setAutoSortOnCell(cell, sortBy)

将数据透视表设置为使用指定的单元格自动进行排序, 以自动选择所有必需的条件和上下文。Sets the PivotTable to automatically sort using the specified cell to automatically select all necessary criteria and context. 这与从 UI 应用自动排序的行为相同。This behaves identically to applying an autosort from the UI.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

setAutoSortOnCell(cell: Range | string, sortBy: Excel.SortBy): void;

参数

cell
Range | string

要使用的单个单元格获取应用自动排序的条件。A single cell to use get the criteria from for applying the autosort.

sortBy
Excel.SortBy

排序的方向。The direction of the sort.

返回

void

setAutoSortOnCell(cell, sortByString)

将数据透视表设置为使用指定的单元格自动进行排序, 以自动选择所有必需的条件和上下文。Sets the PivotTable to automatically sort using the specified cell to automatically select all necessary criteria and context. 这与从 UI 应用自动排序的行为相同。This behaves identically to applying an autosort from the UI.

[API 集: ExcelApi 1.9][ API set: ExcelApi 1.9 ]

setAutoSortOnCell(cell: Range | string, sortByString: "Ascending" | "Descending"): void;

参数

cell
Range | string

要使用的单个单元格获取应用自动排序的条件。A single cell to use get the criteria from for applying the autosort.

sortByString
"Ascending" | "Descending"

排序的方向。The direction of the sort.

返回

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给它的对象的方法。尽管原始 PivotLayout 对象是 API 对象, 但toJSON方法返回一个无格式的 JavaScript 对象 (类型为Excel.Interfaces.PivotLayoutData, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.PivotLayout object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.PivotLayoutData), 其中包含原始对象中所有已加载的子属性的浅表副本。) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.PivotLayoutData;

返回