タイムラインを挿入

可能な使用シナリオ

日付を表示するためにフィルタを調整する代わりに、PivotTableタイムラインを使用できます。これは、日付/時刻でフィルタリングすることが容易になり、スライダー コントロールで望む期間にズームインできるダイナミックフィルタオプションです。Microsoft Excelでは、ピボットテーブルを選択して挿入 > タイムラインをクリックしてタイムラインを作成できます。Aspose.Cells for Javaでは、[Worksheet.getTimelines.add()]メソッドを使用してタイムラインを作成することができます。

ピボットテーブルにタイムラインを作成する

次のサンプルコードを参照してください。ピボットテーブルを含むサンプルExcelファイルをロードし、最初の基本ピボットフィールドに基づいてタイムラインを作成します。最後に、出力XLSX形式でワークブックを保存します。次のスクリーンショットは、Aspose.Cellsによって出力されたExcelファイル内のタイムラインを示しています。

サンプルコード

// 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("input.xlsx");
// Access second worksheet.
Worksheet sheet = wb.getWorksheets().get(1);
//Access PivotTable collection inside the worksheet
PivotTableCollection pivots = sheet.getPivotTables();
// Access first pivot table
PivotTable pivot = pivots.get(0);
//Access Timeline collection inside the worksheet
TimelineCollection timelines = sheet.getTimelines();
// Add timeline relating to pivot table
int index = timelines.add(pivot, 15, 1, "Ship Date");
// Access the newly added timeline from timeline collection.
Timeline timeline = timelines.get(index);
wb.save("output.xlsx");