スライサーを挿入
Contents
[
Hide
]
考えられる使用シナリオ
スライサーは、データをすばやくフィルター処理するために使用されます。テーブルまたはピボット テーブルの両方でデータをフィルター処理するために使用できます。 Microsoft Excel では、テーブルまたはピボット テーブルを選択してから、挿入 > スライサーAspose.Cells を使用してスライサーを作成することもできますWorksheet.Slicers.Add()方法。
ピボット テーブルにスライサーを作成する
以下のサンプルコードをご覧ください。それはサンプル Excel ファイルピボットテーブルが含まれています。次に、最初のベース ピボット フィールドに基づいてスライサーを作成します。最後に、ワークブックを出力 XLSXと出力 XLSBフォーマット。次のスクリーンショットは、出力 Excel ファイルで Aspose.Cells によって作成されたスライサーを示しています。
サンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Load sample Excel file containing pivot table. | |
Workbook wb = new Workbook("sampleCreateSlicerToPivotTable.xlsx"); | |
// Access first worksheet. | |
Worksheet ws = wb.Worksheets[0]; | |
// Access first pivot table inside the worksheet. | |
Aspose.Cells.Pivot.PivotTable pt = ws.PivotTables[0]; | |
// Add slicer relating to pivot table with first base field at cell B22. | |
int idx = ws.Slicers.Add(pt, "B22", pt.BaseFields[0]); | |
// Access the newly added slicer from slicer collection. | |
Aspose.Cells.Slicers.Slicer slicer = ws.Slicers[idx]; | |
// Save the workbook in output XLSX format. | |
wb.Save("outputCreateSlicerToPivotTable.xlsx", SaveFormat.Xlsx); | |
// Save the workbook in output XLSB format. | |
wb.Save("outputCreateSlicerToPivotTable.xlsb", SaveFormat.Xlsb); |
Excel テーブルへのスライサーの作成
以下のサンプルコードをご覧ください。それはサンプル Excel ファイルテーブルが含まれています。次に、最初の列に基づいてスライサーを作成します。最後に、ワークブックを出力 XLSXフォーマット。
サンプルコード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Load sample Excel file containing a table. | |
Workbook workbook = new Workbook(sourceDir + "sampleCreateSlicerToExcelTable.xlsx"); | |
// Access first worksheet. | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Access first table inside the worksheet. | |
ListObject table = worksheet.ListObjects[0]; | |
// Add slicer | |
int idx = worksheet.Slicers.Add(table, 0, "H5"); | |
// Save the workbook in output XLSX format. | |
workbook.Save(outputDir + "outputCreateSlicerToExcelTable.xlsx", SaveFormat.Xlsx); |