ピボット接続を追加する

可能な使用シナリオ

Excelでスライサとピボットテーブルを関連付けたい場合は、スライサを右クリックし、「レポートの接続…」項目を選択する必要があります。オプションリストでチェックボックスで操作できます。同様に、Aspose.Cells for Python via .NET APIを使用してプログラム的にスライサとピボットテーブルを関連付けたい場合は、Slicer.add_pivot_connection(pivot)メソッドを使用してください。これにより、スライサとピボットテーブルが関連付けられます。

Aspose.Cells for Python Excelライブラリを使用してスライサとピボットテーブルを関連付ける方法

次のサンプルコードは、既存のスライサーが含まれるsample Excelファイルを読み込みます。次に、スライサーにアクセスしてスライサーとピボットテーブルを関連付けます。最後に、ワークブックをoutput Excelファイルとして保存します。

サンプルコード

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")