Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Next, add PivotTableFields to the PivotTable. There are four types of PivotTableField: DataFields, RowLabels, ColumnLabels, and PageFields (or report filters). The Pivot field properties are available for all four types of PivotTableField, however some properties will not have an affect, depending on the type of field. These properties can be read and written to, but they will be ignored by Excel.

PageFields

Adding a page field - behavior

All PivotTableFields are created from SourceFields. A SourceField is a read-only field that is automatically generated from the data source of the PivotTable. Each column in the data source corresponds with a SourceField in the PivotTable and the name of the SourceField comes from the column header name.

Note

A SourceField can be used to create one PageField, ColumnLabel, or RowLabel, in addition to an unlimited number of DataFields.

PageFields

To add a PageField, call CreateField on the PivotTable.PageFields collection. You will need to specify the SourceField that will be used to create the PageField.

Code Block

INSERT PageField CODE HERE
Info

PageFields are always placed two rows above the upper left corner of the PivotTable, so if a PivotTable is placed in cell B10, then page fields will be in B8. Any additional PageFields are added to B8 and existing PageFields are moved up a row (B7, B6 and so on).

If there is no space to add the PageFields above the PivotTable (i.e. the PivotTable is located in cell A1), then ExcelWriter will automatically move the PivotTable down to accommodate the PageFields.

RowLabels and ColumnLabels

...