查找并刷新父数据透视表的嵌套或子数据透视表

可能的使用场景

有时,一个数据透视表使用另一个数据透视表作为数据源,因此称为子数据透视表或嵌套数据透视表。您可以使用以下命令找到父数据透视表的子数据透视表数据透视表.GetChildren()方法。

查找并刷新父数据透视表的嵌套或子数据透视表

下面的示例代码加载示例 Excel 文件包含三个数据透视表。底部的两个数据透视表是上述数据透视表的子项,如屏幕截图所示。该代码使用数据透视表.GetChildren()方法,然后一一刷新。

待办事项:图片_替代_文本

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
//Load sample Excel file
Workbook wb = new Workbook("sampleFindAndRefreshNestedOrChildrenPivotTables.xlsx");
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Access third pivot table
PivotTable ptParent = ws.PivotTables[2];
//Access the children of the parent pivot table
PivotTable[] ptChildren = ptParent.GetChildren();
//Refresh all the children pivot table
int count = ptChildren.Length;
for (int idx = 0; idx < count; idx++)
{
//Access the child pivot table
PivotTable ptChild = ptChildren[idx];
//Refresh the child pivot table
ptChild.RefreshData();
ptChild.CalculateData();
}