Excel.PivotField class
Represents the Excel PivotField.
- Extends
Remarks
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. |
items | Returns the PivotItems associated with the PivotField. |
name | Name of the PivotField. |
show |
Determines whether to show all items of the PivotField. |
subtotals | Subtotals of the PivotField. |
Methods
apply |
Sets one or more of the field's current PivotFilters and applies them to the field. If the provided filters are invalid or cannot be applied, an exception is thrown. |
clear |
Clears all criteria from all of the field's filters. This removes any active filtering on the field. |
clear |
Clears all existing criteria from the field's filter of the given type (if one is currently applied). |
clear |
Clears all existing criteria from the field's filter of the given type (if one is currently applied). |
get |
Gets all filters currently applied on the field. |
is |
Checks if there are any applied filters on the field. |
is |
Checks if there are any applied filters on the field. |
load(options) | Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
load(property |
Queues up a command to load the specified properties of the object. You must call |
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. |
sort |
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. |
sort |
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. |
sort |
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. |
toJSON() | Overrides the JavaScript |
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
items
Returns the PivotItems associated with the PivotField.
readonly items: Excel.PivotItemCollection;
Property Value
Remarks
name
showAllItems
Determines whether to show all items of the PivotField.
showAllItems: boolean;
Property Value
boolean
Remarks
subtotals
Subtotals of the PivotField.
subtotals: Excel.Subtotals;
Property Value
Remarks
Method Details
applyFilter(filter)
Sets one or more of the field's current PivotFilters and applies them to the field. If the provided filters are invalid or cannot be applied, an exception is thrown.
applyFilter(filter: Excel.PivotFilters): void;
Parameters
- filter
- Excel.PivotFilters
A configured specific PivotFilter, or a PivotFilters interface containing multiple configured filters.
Returns
void
Remarks
clearAllFilters()
Clears all criteria from all of the field's filters. This removes any active filtering on the field.
clearAllFilters(): void;
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-pivotfilters.yaml
await Excel.run(async (context) => {
// Clear all the PivotFilters.
// Get the PivotTable.
const pivotTable = context.workbook.worksheets.getActiveWorksheet().pivotTables.getItem("Farm Sales");
pivotTable.hierarchies.load("name");
await context.sync();
// Clear the filters on each PivotField.
pivotTable.hierarchies.items.forEach((hierarchy) => {
hierarchy.fields.getItem(hierarchy.name).clearAllFilters();
});
await context.sync();
});
clearFilter(filterType)
Clears all existing criteria from the field's filter of the given type (if one is currently applied).
clearFilter(filterType: Excel.PivotFilterType): void;
Parameters
- filterType
- Excel.PivotFilterType
The type of filter on the field of which to clear all criteria.
Returns
void
Remarks
clearFilter(filterTypeString)
Clears all existing criteria from the field's filter of the given type (if one is currently applied).
clearFilter(filterTypeString: "Unknown" | "Value" | "Manual" | "Label" | "Date"): void;
Parameters
- filterTypeString
-
"Unknown" | "Value" | "Manual" | "Label" | "Date"
The type of filter on the field of which to clear all criteria.
Returns
void
Remarks
getFilters()
Gets all filters currently applied on the field.
getFilters(): OfficeExtension.ClientResult<Excel.PivotFilters>;
Returns
A PivotFilters interface with all active filters.
Remarks
isFiltered(filterType)
Checks if there are any applied filters on the field.
isFiltered(filterType?: Excel.PivotFilterType): OfficeExtension.ClientResult<boolean>;
Parameters
- filterType
- Excel.PivotFilterType
The filter type to check. If no type is provided, this method will check if any filter is applied.
Returns
OfficeExtension.ClientResult<boolean>
True if the field has a filter of type filterType
applied. If filterType
is not specified, true
is returned if the field has any applied filters.
Remarks
isFiltered(filterTypeString)
Checks if there are any applied filters on the field.
isFiltered(filterTypeString?: "Unknown" | "Value" | "Manual" | "Label" | "Date"): OfficeExtension.ClientResult<boolean>;
Parameters
- filterTypeString
-
"Unknown" | "Value" | "Manual" | "Label" | "Date"
The filter type to check. If no type is provided, this method will check if any filter is applied.
Returns
OfficeExtension.ClientResult<boolean>
True if the field has a filter of type filterType
applied. If filterType
is not specified, true
is returned if the field has any applied filters.
Remarks
load(options)
Queues up a command to load the specified properties of the object. You must call context.sync()
before reading the properties.
load(options?: Excel.Interfaces.PivotFieldLoadOptions): Excel.PivotField;
Parameters
Provides options for which properties of the object to load.
Returns
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; }
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
- Excel.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
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.
sortByLabels(sortBy: SortBy): void;
Parameters
- sortBy
- Excel.SortBy
Specifies if the sorting is done in ascending or descending order.
Returns
void
Remarks
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.
sortByValues(sortBy: Excel.SortBy, valuesHierarchy: Excel.DataPivotHierarchy, pivotItemScope?: Array<PivotItem | string>): void;
Parameters
- sortBy
- Excel.SortBy
Specifies if the sorting is done in ascending or descending order.
- valuesHierarchy
- Excel.DataPivotHierarchy
Specifies the values hierarchy on the data axis to be used for sorting.
- pivotItemScope
-
Array<Excel.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
Remarks
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.
sortByValues(sortByString: "Ascending" | "Descending", valuesHierarchy: Excel.DataPivotHierarchy, pivotItemScope?: Array<PivotItem | string>): void;
Parameters
- sortByString
-
"Ascending" | "Descending"
Specifies if the sorting is done in ascending or descending order.
- valuesHierarchy
- Excel.DataPivotHierarchy
Specifies the values hierarchy on the data axis to be used for sorting.
- pivotItemScope
-
Array<Excel.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
Remarks
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
Office Add-ins