ピボットテーブルにスライサーを作成する

可能な使用シナリオ

スライサーはデータを素早くフィルタリングするために使用されます。テーブルまたはピボットテーブルでデータをフィルタリングするために使用できます。Aspose.Cellsを使用すると、Worksheet.getSlicers().add()メソッドを使用してスライサーを作成することもできます。

ピボットテーブルにスライサーを作成する

次のサンプルコードをご覧ください。ピボットテーブルが含まれるsample Excel fileをロードします。次に、最初の基本ピボットフィールドに基づいてスライサーを作成します。最後に、output XLSXおよびoutput XLSB形式のワークブックを保存します。スクリーンショットをご覧になりますが、Aspose.Cellsによって作成されたスライサーが出力されたExcelファイルに表示されます。

todo:image_alt_text

サンプルコード

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Load sample Excel file containing pivot table.
Workbook wb = new Workbook(srcDir + "sampleCreateSlicerToPivotTable.xlsx");
// Access first worksheet.
Worksheet ws = wb.getWorksheets().get(0);
// Access first pivot table inside the worksheet.
PivotTable pt = ws.getPivotTables().get(0);
// Add slicer relating to pivot table with first base field at cell B22.
int idx = ws.getSlicers().add(pt, "B22", pt.getBaseFields().get(0));
// Access the newly added slicer from slicer collection.
Slicer slicer = ws.getSlicers().get(idx);
// Save the workbook in output XLSX format.
wb.save(outDir + "outputCreateSlicerToPivotTable.xlsx", SaveFormat.XLSX);
// Save the workbook in output XLSB format.
wb.save(outDir + "outputCreateSlicerToPivotTable.xlsb", SaveFormat.XLSB);