[]
Represents a field in a PivotTable report.
An IPivotField is a member of the IPivotFields collection and
describes how a source field is used in a PivotTable report, including hidden
fields. Use this interface to access field metadata, change field orientation,
configure sorting and filtering, and work with row, column, page, or data fields.
public interface IPivotField
Public Interface IPivotField
worksheet.Range["A1:B5"].Value = new object[,] {
{"Category", "Amount"},
{"Fruit", 120},
{"Fruit", 80},
{"Vegetables", 95},
{"Vegetables", 60}
};
IPivotCache pivotCache = workbook.PivotCaches.Create(worksheet.Range["A1:B5"]);
IPivotTable pivotTable = worksheet.PivotTables.Add(pivotCache, worksheet.Range["D1"], "SalesPivot");
IPivotField field = pivotTable.PivotFields["Category"];
field.Orientation = PivotFieldOrientation.RowField;
| Name | Description |
|---|---|
| AllItemsVisible | Gets whether all items in the PivotField are visible. Returns false when manual filtering has been applied by hiding one or more items. Use ClearManualFilter() to restore visibility to all items. |
| AutoSortField | Gets the name of the data field used to sort this PivotTable field automatically. If automatic sorting is configured by AutoSort(SortOrder?, string), this property returns the sort key field name that was specified for that rule. |
| AutoSortOrder | Gets the automatic sort order of this PivotTable field. If automatic sorting is configured by AutoSort(SortOrder?, string), this property returns the SortOrder applied to the field. |
| BaseField | Gets or sets the name of the base field used for a custom calculation. This property is valid only for data fields. Use this property together with Calculation when the data field is configured to show values by a custom calculation such as PercentOf. |
| BaseItem | Gets or sets the item in the base field for a custom calculation. This property is valid only for data fields. Use this property together with BaseField and Calculation to determine which item in the base field is used by a custom calculation such as PercentOf. |
| Calculation | Gets or sets a PivotFieldCalculation value that represents the type of calculation performed by the specified field. This property is valid only for data fields. |
| CurrentPage | Gets or sets the index of the current page item displayed for the page field.
This method is valid only for page fields. The returned index is zero-based.
A value of |
| DragToColumn | Gets or sets whether the specified field can be dragged to the column position. This property indicates whether the field can be moved into the column area of a PivotTable report. The default value is |
| DragToData | Gets or sets whether the specified field can be dragged to the data position. This property indicates whether the field can be moved into the data area of a PivotTable report. The default value is |
| DragToHide | Gets or sets whether the field can be hidden by being dragged off the PivotTable report. This property indicates whether users can remove the field from the PivotTable report by dragging it away. The default value is |
| DragToPage | Gets or sets whether the field can be dragged to the page position. The default value is true. |
| DragToRow | Gets or sets whether the field can be dragged to the row position. This property determines whether the field is allowed to be moved to the row area in a PivotTable. The default value is true. |
| EnableMultiplePageItems | Gets or sets whether the field can have multiple items selected in the page field. This property applies to PivotTable fields that are placed in the page area. The default value is false. |
| Formula | Gets or sets the formula of the PivotTable field in A1-style notation and in the language of the macro. This property returns the formula text associated with the field. |
| Function | Gets or sets the summary function used by this PivotTable field. |
| LayoutBlankLine | Gets or sets whether a blank row is inserted after this row field in a PivotTable report. This property applies to PivotFields placed in the row area of a PivotTable. The default value is false. |
| LayoutCompactRow | Gets or sets whether this PivotField uses compact row layout when it is placed in the row area. When this property is true, items from multiple row PivotFields can be displayed in a single column. |
| LayoutForm | Gets or sets the way the specified PivotTable items appear. Use this property to determine whether the field is displayed in table format or outline format. |
| LayoutSubtotalLocation | Gets or sets the position of the PivotTable field subtotals in relation to the specified field. Use this property to determine whether subtotals for the field are displayed above or below the field items. |
| Name | Gets or sets the name of the object. Use this property to retrieve the current name of a field in a PivotTable report. |
| NumberFormat | Gets or sets the number format code for the pivot field. |
| Orientation | Gets or sets the location of the field in the specified PivotTable report. Use this property to determine whether the field is currently placed in the row, column, page, data, or hidden area of the PivotTable. |
| PivotFilters | Gets the pivot filter collection for this IPivotField. |
| PivotItems | Gets the collection of all visible and hidden items in this PivotTable field. Use this collection to access individual field items, including items that are currently hidden by manual filtering. |
| Position | Gets or sets the position of the field among the fields in its current orientation. The position determines the order of the field within its orientation area, such as row fields, column fields, page fields, or data fields. |
| RepeatLabels | Gets or sets whether item labels are repeated in the PivotTable for the specified IPivotField. Use this property to determine whether repeated item labels are shown for the field in the PivotTable layout. |
| ShowAllItems | Gets or sets whether all items in the PivotTable report are displayed, even if they do not contain summary data. The default value is false. When this property is true, items without summarized values are still shown for the PivotField. |
| SourceName | Gets the field name as it appears in the original source data. This value identifies the underlying source field for the PivotTable report. It can differ from the current display name returned by Name if the field has been renamed by using Name. |
| Subtotals | Gets or sets the combination of subtotal types currently shown for this PivotField. This method is valid only for nondata fields. Use it to inspect which SubtotalType values are enabled for the field. |
| Name | Description |
|---|---|
| AutoSort(SortOrder?, string) | Establishes automatic field-sorting rules for a PivotTable field. Use this method to apply automatic ascending or descending sorting to the current field in a PivotTable report. |
| CalculatedItems() | Gets the collection of calculated items for this IPivotField. The returned ICalculatedItems collection represents all calculated items defined for the current PivotTable field and can be used to access or add calculated items. |
| ClearAllFilters() | Deletes all filters currently applied to this PivotField. This method removes all filters from the PivotFilters collection and also clears any manual filtering applied to the field. If the field is in the report filter area, the selected item is reset to the default item. |
| ClearLabelFilter() | Clears all label filters or date filters from this pivot field. This method removes the label-based filter criteria stored in the pivot field's PivotFilters collection. Use this method when you want to keep other filter types, such as value filters, unchanged. |
| ClearManualFilter() | Clears manual filtering from the PivotField. This method sets the visible state of all items in the field to visible in PivotTables. For OLAP PivotTables, it also clears the hidden and visible item lists used by manual filtering. |
| ClearValueFilter() | Clears all value filters from this pivot field. This method removes value-based filter criteria from the pivot field's PivotFilters collection. Use this method when you want to clear value filters without removing label filters or manual filtering. |
| Group(PivotFieldCustomGroupOptions) | Creates a custom group from PivotItems in the PivotField. |
| Group(PivotFieldDateGroupOptions) | Groups the PivotField by date or time units. |
| Group(PivotFieldNumberGroupOptions) | Groups the PivotField into numeric ranges. |
| Ungroup() | Removes grouping from the pivot field. |