读取和操作Excel 2016图表

可能的使用场景

Aspose.Cells for Python via .NET现在支持读取和操作Microsoft Excel 2016图表,该功能在Microsoft Excel 2013或更早版本中不可用。

读取和操作Excel 2016图表

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

todo:image_alt_text

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

todo:image_alt_text

示例代码

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Load source excel file containing excel 2016 charts
book = Workbook(dataDir + "excel2016Charts.xlsx")
# Access the first worksheet which contains the charts
sheet = book.worksheets[0]
# Access all charts one by one and read their types
for i in range(len(sheet.charts)):
# Access the chart
ch = sheet.charts[i]
# Print chart type
print(ch.type)
# Change the title of the charts as per their types
ch.title.text = "Chart Type is " + str(ch.type)
# Save the workbook
book.save(dataDir + "out_excel2016Charts.xlsx")

控制台输出

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

 Waterfall

Treemap

Sunburst

Histogram

BoxWhisker

高级主题