ピボット テーブルにスライサーを作成する
Contents
[
Hide
]
考えられる使用シナリオ
スライサーは、データをすばやくフィルター処理するために使用されます。これらは、テーブルまたはピボット テーブルの両方でデータをフィルター処理するために使用できます。 Microsoft Excel では、テーブルまたはピボット テーブルを選択してから、挿入 > スライサー. Aspose.Cells for Python via Java は、スライサーを作成するための Worksheet.getSlicers().add() メソッドを提供します。
ピボット テーブルにスライサーを作成する
次のコード スニペットは、サンプル Excel ファイルピボットテーブルが含まれています。次に、最初のベース ピボット フィールドに基づいてスライサーを作成します。最後に、ワークブックを出力 XLSXフォーマット。次のスクリーンショットは、出力 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
import jpype | |
import asposecells | |
jpype.startJVM() | |
from asposecells.api import Workbook, SaveFormat | |
# Load Source Excel file | |
workbook = Workbook("sampleCreateSlicerToPivotTable.xlsx") | |
# Access first worksheet | |
worksheet = workbook.getWorksheets().get(0) | |
# Access first pivot table inside the worksheet | |
pivottable = worksheet.getPivotTables().get(0) | |
# Add slicer relating to pivot table with first base field at cell B22 | |
idx = worksheet.getSlicers().add(pivottable, "B22", pivottable.getBaseFields().get(0)) | |
# Access the newly added slicer from slicer collection | |
slicer = worksheet.getSlicers().get(idx) | |
# Save the workbook in output XLSX format | |
workbook.save("outputCreateSlicerToPivotTable.xlsx", SaveFormat.XLSX) | |
jpype.shutdownJVM() |