PivotFields

class PivotFields

The fields in one area of a pivot table, i.e. pt.rows, pt.columns or pt.filters. Iteration follows the field order.

>>> pt = xw.books['Book1'].sheets[0].pivot_tables[0]
>>> pt.rows
PivotFields([<PivotField 'Region' in 'PivotTable1'>])
>>> pt.rows[0]  # or pt.rows['Region']
<PivotField 'Region' in 'PivotTable1'>

Added in version 0.37.3.

add(name)

Places a source field in this area, after the existing fields.

A field that is already in this area stays where it is; a field in another of the rows/columns/filters areas is moved here.

Parameters:

name (str) – Name of the source field, see PivotTable.field_names.

Return type:

PivotField

property parent: PivotTable

Returns the pivot table the area belongs to.