添加数据透视连接
Contents
[
Hide
]
可能的使用场景
如果您想要在Excel中关联切片器和数据透视表,您需要右键单击切片器并选择“报告连接…”选项。在选项列表中,您可以操作复选框。同样,如果您想要使用Aspose.Cells for Python via .NET API以编程方式关联切片器和数据透视表,请使用Slicer.add_pivot_connection(pivot)方法。它将关联切片器和数据透视表。
如何使用Aspose.Cells for Python Excel库关联切片器和数据透视表
以下示例代码加载包含现有切片器的sample Excel file。它访问切片器然后将切片器与数据透视表关联。最后,将工作簿另存为output Excel file。
示例代码
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 containing slicer. | |
wb = Workbook("add-pivot-connection .xlsx") | |
# Access first worksheet. | |
ws = wb.worksheets[0] | |
# Access the first PivotTable inside the PivotTable collection. | |
pivottable = ws.pivot_tables[0] | |
# Access the first slicer inside the slicer collection. | |
slicer = ws.slicers[0] | |
# Adds PivotTable connection. | |
slicer.add_pivot_connection(pivottable) | |
wb.save("add-pivot-connection-out.xlsx") |