Page tree

Versions Compared

Key

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

...

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
            pivot.PageFields.CreateField(dateStart);
            pivot.PageFields.CreateField(dateEnd);
Info

Page fields are always placed starting two rows above the upper left corner of the PivotTable, so if a PivotTable is placed in cell B10, then page fields will be start in B8. Any additional page fields are added to B8 and existing page fields are moved up a row (B7, B6 and so on). , or the new page field is added to a column to the right, depending on the page layout properties in the PivotTable.

By default, all the page fields appear in one column.

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

...

Similarly to page fields, RowLabels and ColumnLabels are created on the PivotTable.RowLabels and PivotTable.ColumnLabels collections. As mentioned earlier, only one RowLabel, ColumnLabel, or PageField can be created from a particular SourceField.

Code Block
Insert column label and row label code here
PivotTableField prodSubCategoryFld = pt.RowLabels.CreateField(prodSubCategory);
     PivotTableField prodNameFld = pt.RowLabels.CreateField(prodName);
     PivotTableField salesFld = pt.RowLabels.CreateField(sales);

Row labels and column labels display the subtotals for each group of values. The subtotal can be displayed at the top or bottom of the group.

Code Block

     pivot.PageFields.CreateField(dateStart);
     pivot.PageFields.CreateField(dateEnd);

Excel automatically sorts and re-renders a PivotTable any time a change is made. By default, the row label or column label values are sorted alpha-numerically in ascending order.

...