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

考えられる使用シナリオ

スライサーは、データをすばやくフィルター処理するために使用されます。テーブルまたはピボット テーブルの両方でデータをフィルター処理するために使用できます。 Microsoft Excel では、テーブルまたはピボット テーブルを選択してから、挿入 > スライサーAspose.Cells を使用してスライサーを作成することもできます[Worksheet.getSlicers().add()](https://reference.aspose.com/cells/java/com.aspose.cells/slicercollection#add(com.aspose.cells.PivotTable,%20int,%20int,%20com.aspose.cells.PivotField)) 方法。

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

以下のサンプルコードをご覧ください。それはサンプル Excel ファイルピボットテーブルが含まれています。次に、最初のベース ピボット フィールドに基づいてスライサーを作成します。最後に、ワークブックを出力 XLSX出力 XLSBフォーマット。次のスクリーンショットは、出力 Excel ファイルで Aspose.Cells によって作成されたスライサーを示しています。

todo:画像_代替_文章

サンプルコード

// 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);