读取和操作Excel 2016图表

可能的使用场景

Aspose.Cells 现在支持读取和操作 Microsoft Excel 2016 图表,而这些图表在 Microsoft Excel 2013 或早期版本中是不存在的。

读取和操作Excel 2016图表

以下示例代码加载了包含 Excel 2016 图表的 源 Excel 文件 并将其显示在第一个工作表中。它逐个读取所有图表,按照其图表类型更改标题。下面的屏幕截图显示了代码执行前的源 Excel 文件。正如您所见,所有图表的图表标题都是相同的。

todo:image_alt_text

下面的屏幕截图显示了代码执行后的 输出 Excel 文件。正如您所见,图表标题已根据其图表类型进行了更改。

todo:image_alt_text

示例代码

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
// Load source excel file containing excel 2016 charts
Workbook book = new Workbook(dataDir + "excel2016Charts.xlsx");
// Access the first worksheet which contains the charts
Worksheet sheet = book.Worksheets[0];
// Access all charts one by one and read their types
for (int i = 0; i < sheet.Charts.Count; i++)
{
// Access the chart
Chart ch = sheet.Charts[i];
// Print chart type
Console.WriteLine(ch.Type);
// Change the title of the charts as per their types
ch.Title.Text = "Chart Type is " + ch.Type.ToString();
}
// Save the workbook
book.Save(dataDir + "out_excel2016Charts.xlsx");

控制台输出

以下是使用所提供的 源 Excel 文件 执行上述示例代码时的控制台输出。

 Waterfall

Treemap

Sunburst

Histogram

BoxWhisker

高级主题