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

可能的使用场景

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

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

以下是加载包含三个数据透视表的样本Excel文件的示例代码。下面两个数据透视表是上面数据透视表的子级,如此屏幕截图所示。代码使用PivotTable.GetChildren()方法查找子级数据透视表,然后逐个刷新它们。

todo:image_alt_text

示例代码

// 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();
}