查找并刷新父数据透视表的嵌套或子数据透视表
Contents
[
Hide
]
可能的使用场景
有时,一个数据透视表使用另一个数据透视表作为数据源,因此被称为子数据透视表或嵌套数据透视表。您可以使用PivotTable.get_children()方法找到父数据透视表的子数据透视表。
如何使用Aspose.Cells for Python via .NET查找并刷新父数据透视表的嵌套或子数据透视表
以下是加载包含三个数据透视表的样本Excel文件的示例代码。下面两个数据透视表是上面数据透视表的子级,如此屏幕截图所示。代码使用PivotTable.get_children()方法查找子级数据透视表,然后逐个刷新它们。
示例代码
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
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() |