WPS 基础接口 > 表格 API 参考 > PivotCell > PivotCell 对象

代表数据透视表中的一个单元格。

说明

使用 Range 集合的 PivotCell 属性可返回一个 PivotCell 对象。

返回 PivotCell 对象后,可以使用 ColumnItemsRowItems 属性来确定 PivotItems 集合,对应于代表所选编号的列轴或行轴上的项目。下例使用 PivotCell 对象的 ColumnItems 属性来返回一个 PivotItemList 集合。

示例

返回了 PivotCell 对象后,可以使用 PivotCellType 属性来确定某个特定区域是什么单元格类型。下例确定数据透视表中的单元格 A5 是否是数据项目并通知用户。此示例假定活动工作表上存在数据透视表而且单元格 A5 包含在该数据透视表中。如果单元格 A5 不在数据透视表中,该示例会处理运行时错误。

示例代码
function CheckPivotCellType() {

    try {
        // Determine if cell A5 is a data item in the PivotTable.
        if(Application.Range("A5").PivotCell.PivotCellType == xlPivotCellValue) {
            MsgBox ("The PivotCell at A5 is a data item.")
        }
        else {
            MsgBox ("The PivotCell at A5 is a data item.")
        }
    }
									
    catch(exception){
        MsgBox("The chosen cell is not in a PivotTable.")
    }
									
}

此示例确定单元格 B5 的数据项所在的列字段。然后判断列字段标题是否与“Inventory”相匹配,并通知用户。此示例假定数据透视表位于活动工作表上,并且工作表的 B 列包含数据透视表的列字段。

示例代码
function  CheckColumnItems() {

    // Determine if there is a match between the item and column field.
    if(Application.Range("B5").PivotCell.ColumnItems.Item(1) == "Inventory") {
        MsgBox ("Item in B5 is a member of the 'Inventory' column field.")
    }
    else {
        MsgBox ("Item in B5 is not a member of the 'Inventory' column field.")
    }
									
}


请参阅