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

可能的使用场景

有时,一个数据透视表使用另一个数据透视表作为数据源,因此被称为子数据透视表或嵌套数据透视表。您可以使用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-Java
//Load sample Excel file
Workbook wb = new Workbook("sampleFindAndRefreshNestedOrChildrenPivotTables.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access third pivot table
PivotTable ptParent = ws.getPivotTables().get(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();
}