Excel.PivotField class

Represents the Excel PivotField.

[ API set: ExcelApi 1.8 ]

Extends
OfficeExtension.ClientObject

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

id

Id of the PivotField.

[ API set: ExcelApi 1.8 ]

items

Returns the PivotFields associated with the PivotField.

[ API set: ExcelApi 1.8 ]

name

Name of the PivotField.

[ API set: ExcelApi 1.8 ]

showAllItems

Determines whether to show all items of the PivotField.

[ API set: ExcelApi 1.8 ]

subtotals

Subtotals of the PivotField.

[ API set: ExcelApi 1.8 ]

Methods

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(propertyNames)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

set(properties, options)

Sets multiple properties of an object at the same time. 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.

sortByLabels(sortBy)

Sorts the PivotField. If a DataPivotHierarchy is specified, then sort will be applied based on it, if not sort will be based on the PivotField itself.

[ API set: ExcelApi 1.8 ]

sortByValues(sortBy, valuesHierarchy, pivotItemScope)

Sorts the PivotField by specified values in a given scope. The scope defines which specific values will be used to sort when there are multiple values from the same DataPivotHierarchy.

[ API set: ExcelApi 1.9 ]

sortByValues(sortByString, valuesHierarchy, pivotItemScope)

Sorts the PivotField by specified values in a given scope. The scope defines which specific values will be used to sort when there are multiple values from the same DataPivotHierarchy.

[ API set: ExcelApi 1.9 ]

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.PivotField object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.PivotFieldData) that contains shallow copies of any loaded child properties from the original object.

Property Details

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

context: RequestContext;

Property Value

id

Id of the PivotField.

[ API set: ExcelApi 1.8 ]

readonly id: string;

Property Value

string

items

Returns the PivotFields associated with the PivotField.

[ API set: ExcelApi 1.8 ]

readonly items: Excel.PivotItemCollection;

Property Value

name

Name of the PivotField.

[ API set: ExcelApi 1.8 ]

name: string;

Property Value

string

showAllItems

Determines whether to show all items of the PivotField.

[ API set: ExcelApi 1.8 ]

showAllItems: boolean;

Property Value

boolean

subtotals

Subtotals of the PivotField.

[ API set: ExcelApi 1.8 ]

subtotals: Excel.Subtotals;

Property Value

Method Details

load(option)

Queues up a command to load the specified properties of the object. You must call "context.sync()" before reading the properties.

load(option?: Excel.Interfaces.PivotFieldLoadOptions): Excel.PivotField;

Parameters

Returns

Remarks

In addition to this signature, this method has the following signatures:

load(option?: string | string[]): Excel.PivotField - 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.PivotField - 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.PivotField - Only available on collection types. It is similar to the preceding signature. Option.top specifies the maximum number of collection items that can be included in the result. Option.skip specifies the number of items that are to be skipped and not included in the result. 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. You must call context.sync() before reading the properties.

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

Parameters

propertyNames
string | string[]

A comma-delimited string or an array of strings that specify the properties to load.

Returns

load(propertyNamesAndPaths)

Queues up a command to load the specified properties of the object. You must call context.sync() before reading the properties.

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

Parameters

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

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.

Returns

set(properties, options)

Sets multiple properties of an object at the same time. You can pass either a plain object with the appropriate properties, or another API object of the same type.

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

Parameters

properties
Interfaces.PivotFieldUpdateData

A JavaScript object with properties that are structured isomorphically to the properties of the object on which the method is called.

options
OfficeExtension.UpdateOptions

Provides an option to suppress errors if the properties object tries to set any read-only properties.

Returns

void

Remarks

This method has the following additional signature:

set(properties: Excel.PivotField): void

set(properties)

Sets multiple properties on the object at the same time, based on an existing loaded object.

set(properties: Excel.PivotField): void;

Parameters

properties
Excel.PivotField

Returns

void

sortByLabels(sortBy)

Sorts the PivotField. If a DataPivotHierarchy is specified, then sort will be applied based on it, if not sort will be based on the PivotField itself.

[ API set: ExcelApi 1.8 ]

sortByLabels(sortBy: SortBy): void;

Parameters

sortBy
SortBy

Represents whether the sorting is done in an ascending or descending order.

Returns

void

sortByValues(sortBy, valuesHierarchy, pivotItemScope)

Sorts the PivotField by specified values in a given scope. The scope defines which specific values will be used to sort when there are multiple values from the same DataPivotHierarchy.

[ API set: ExcelApi 1.9 ]

sortByValues(sortBy: Excel.SortBy, valuesHierarchy: Excel.DataPivotHierarchy, pivotItemScope?: Array<PivotItem | string>): void;

Parameters

sortBy
SortBy

Represents whether the sorting is done in an ascending or descending order.

valuesHierarchy
Excel.DataPivotHierarchy

Specifies the values hierarchy on the data axis to be used for sorting.

pivotItemScope
Array<PivotItem | string>

The items that should be used for the scope of the sorting. These will be the items that make up the row or column that you want to sort on. If a string is used instead of a PivotItem, the string represents the ID of the PivotItem. If there are no items other than data hierarchy on the axis you want to sort on, this can be empty.

Returns

void

sortByValues(sortByString, valuesHierarchy, pivotItemScope)

Sorts the PivotField by specified values in a given scope. The scope defines which specific values will be used to sort when there are multiple values from the same DataPivotHierarchy.

[ API set: ExcelApi 1.9 ]

sortByValues(sortByString: "Ascending" | "Descending", valuesHierarchy: Excel.DataPivotHierarchy, pivotItemScope?: Array<PivotItem | string>): void;

Parameters

sortByString
"Ascending" | "Descending"

Represents whether the sorting is done in an ascending or descending order.

valuesHierarchy
Excel.DataPivotHierarchy

Specifies the values hierarchy on the data axis to be used for sorting.

pivotItemScope
Array<PivotItem | string>

The items that should be used for the scope of the sorting. These will be the items that make up the row or column that you want to sort on. If a string is used instead of a PivotItem, the string represents the ID of the PivotItem. If there are no items other than data hierarchy on the axis you want to sort on, this can be empty.

Returns

void

toJSON()

Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that is passed to it.) Whereas the original Excel.PivotField object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.PivotFieldData) that contains shallow copies of any loaded child properties from the original object.

toJSON(): Excel.Interfaces.PivotFieldData;

Returns