PivotValueFields

class PivotValueFields

The fields in the Values area of a pivot table, i.e. pt.values. Iteration follows the field order.

>>> pt = xw.books['Book1'].sheets[0].pivot_tables[0]
>>> pt.values
PivotValueFields([<PivotValueField 'Sum of Sales' in 'PivotTable1'>])
>>> pt.values[0]  # or pt.values['Sum of Sales']
<PivotValueField 'Sum of Sales' in 'PivotTable1'>

在 0.37.3 版被加入.

add(field, function=None, name=None, number_format=None)

Adds a source field to the values area, after the existing value fields. The same source field can be added more than once, e.g. as a sum and as a count.

參數:
  • field (str) -- Name of the source field, see PivotTable.field_names.

  • function (str | None) -- Summary function, see PivotValueField.function. Defaults to Excel's choice: "sum" for numeric fields, "count" otherwise.

  • name (str | None) -- Caption, e.g. "Total Sales". Defaults to Excel's caption, e.g. "Sum of Sales". Excel rejects a name that equals the name of a source field.

  • number_format (str | None) -- Number format, e.g. "#,##0.00".

回傳型別:

PivotValueField

property api: Any

Returns the native object (pywin32 or appscript obj) of the engine being used.

property count: int

Returns the number of objects in the collection.

property parent: PivotTable

Returns the pivot table the area belongs to.