插入时间轴
Contents
[
Hide
]
可能的使用场景
您可以使用数据透视表时间轴动态筛选选项,而不是调整筛选器来显示日期,轻松筛选日期/时间,并使用滑块控件放大您想要的时段。Microsoft Excel允许您通过选择一个数据透视表,然后单击插入 > 时间轴 来创建时间轴。Aspose.Cells for java也允许您使用[Worksheet.getTimelines.add()]方法创建时间轴。
创建时间轴到透视表
请参阅以下示例代码。它加载包含透视表的示例Excel文件,然后根据第一个基本透视字段创建时间轴。最后,它以output XLSX格式保存工作簿。以下截图显示了Aspose.Cells在输出Excel文件中创建的时间轴。

示例代码
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-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"); |