ピボット接続を追加する

可能な使用シナリオ

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

スライサーとピボットテーブルを関連付ける

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

サンプルコード

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Load sample Excel file containing slicer.
Workbook wb = new Workbook("add-pivot-connection .xlsx");
// Access first worksheet.
Worksheet ws = wb.Worksheets[0];
// Access the first PivotTable inside the PivotTable collection.
PivotTable pivottable = ws.PivotTables[0];
// Access the first slicer inside the slicer collection.
Slicer slicer = ws.Slicers[0];
//Adds PivotTable connection.
slicer.AddPivotConnection(pivottable);
wb.Save("add-pivot-connection-out.xlsx");