读取和操作 Excel 2016 图表

可能的使用场景

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

读取和操作 Excel 2016 图表

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

待办事项:图片_替代_文本

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

待办事项:图片_替代_文本

示例代码

// 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");

控制台输出

这是使用提供的执行时上述示例代码的控制台输出源文件.

 Waterfall

Treemap

Sunburst

Histogram

BoxWhisker

推进主题