查找并刷新父数据透视表的嵌套或子数据透视表
Contents
[
Hide
]
可能的使用场景
有时,一个数据透视表使用另一个数据透视表作为数据源,因此被称为子数据透视表或嵌套数据透视表。您可以使用PivotTable.getChildren()方法找到父数据透视表的子数据透视表。
查找并刷新父数据透视表的嵌套或子数据透视表
以下示例代码加载了包含三个数据透视表的示例Excel文件。底部两个数据透视表是上面数据透视表的子数据透视表,如此屏幕截图所示。该代码使用PivotTable.getChildren()方法找到子数据透视表,然后依次刷新它们。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} |