Skip to content
本页内容

DataField (属性)

返回一个 PivotField 对象,该对象与所选数据字段相对应。

说明

如果 PivotCell 对象不是 XlPivotCellType 允许的常量:xlPivotCellTypeDataFieldxlPivotCellTypeSubtotalxlPivotCellTypeGrandTotal 之一,那么该属性将返回一个错误。

示例

python
#本示例确定单元格 I2 是否在数据透视表的数据字段中,然后通过通知用户来返回对应于该单元格的数据透视表字段的值,或处理运行错误。本示例假定数据透视表位于活动工作表上
def test():
    try:
        print(Application.Range("I2").PivotCell.DataField.Value)
    except Exception as e:
        print("The selected range is not in the data field of the PivotTable.")
python
#本示例显示工作表 Sheet1 上第一张数据透视表行轴上第一条数据透视线PivotLineCells属性的第一个PivotCell对象对应字段汇总时所使用的函数是否为 xlSum
def test():
    pvtLine = Worksheets.Item("Sheet1").PivotTables(1).PivotRowAxis.PivotLines(1)
    print(pvtLine.PivotLineCells.Item(1).DataField.Function == xlSum)