插入时间线

可能的使用场景

您可以使用数据透视表时间轴而不是调整过滤器来显示日期——这是一种动态过滤器选项,可让您轻松按日期/时间进行过滤,并使用滑块控件放大您想要的时间段。 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");