插入时间线
Contents
[
Hide
]
可能的使用场景
您可以使用数据透视表时间轴而不是调整过滤器来显示日期——这是一种动态过滤器选项,可让您轻松按日期/时间进行过滤,并使用滑块控件放大您想要的时间段。 Microsoft Excel 允许您通过选择数据透视表然后单击插入 > 时间线. Aspose.Cells 还允许您使用工作表.时间线.Add()方法。
为数据透视表创建时间线
请参阅以下示例代码。它加载了示例 Excel 文件包含数据透视表。然后它根据第一个基本数据透视字段创建时间线。最后,它将工作簿保存在输出 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
// Load sample Excel file containing pivot table. | |
Workbook wb = new Workbook("input.xlsx"); | |
// Access second worksheet. | |
Worksheet sheet = wb.Worksheets[1]; | |
// Access first pivot table inside the worksheet. | |
PivotTable pivot = sheet.PivotTables[0]; | |
// Add timeline relating to pivot table | |
int index = sheet.Timelines.Add(pivot, 15, 1, "Ship Date"); | |
// Access the newly added timeline from timeline collection. | |
Timeline timeline = sheet.Timelines[index]; | |
wb.Save("output.xlsx"); |