ピボット接続を追加する

可能な使用シナリオ

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

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

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

サンプルコード

// Load sample Excel file containing slicer.
Workbook wb = new Workbook("add-pivot-connection .xlsx");
// Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
// Access the first PivotTable inside the PivotTable collection.
PivotTable pivottable = ws.getPivotTables().get(0);
// Access the first slicer inside the slicer collection.
Slicer slicer = ws.getSlicers().get(0);
//Adds PivotTable connection.
slicer.addPivotConnection(pivottable);
wb.save("add-pivot-connection-out.xlsx");