Find and Refresh the Nested or Children Pivot Tables of Parent Pivot Table
Possible Usage Scenarios
Sometimes, one pivot table uses another pivot table as a data source, so it is called a child pivot table or nested pivot table. You can find the children pivot tables of a parent pivot table using the PivotTable.get_children() method.
How to Find and Refresh the Nested or Children Pivot Tables of Parent Pivot Table
The following sample code loads the sample Excel file that contains three pivot tables. The bottom two pivot tables are the children of the above pivot table as shown in this screenshot. The code finds the children pivot table using the PivotTable.get_children() method and then refreshes them one by one.
Sample Code
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Load sample Excel file | |
wb = Workbook("sampleFindAndRefreshNestedOrChildrenPivotTables.xlsx") | |
# Access first worksheet | |
ws = wb.worksheets[0] | |
# Access third pivot table | |
ptParent = ws.pivot_tables[2] | |
# Access the children of the parent pivot table | |
ptChildren = ptParent.get_children() | |
# Refresh all the children pivot table | |
count = len(ptChildren) | |
for idx in range(count): | |
# Access the child pivot table | |
ptChild = ptChildren[idx] | |
# Refresh the child pivot table | |
ptChild.refresh_data() | |
ptChild.calculate_data() |