Excel 2016のチャートの読み込みと操作
可能な使用シナリオ
Aspose.Cells for Python via .NETは、Microsoft Excel 2013以前のバージョンには存在しないMicrosoft Excel 2016のチャートの読み取りおよび操作をサポートしています。
Excel 2016のチャートの読み込みと操作
次のサンプルコードは、最初のワークシートにExcel 2016チャートが含まれるソースエクセルファイルをロードします。すべてのチャートを1つずつ読み取り、そのチャートタイプに応じてタイトルを変更します。次のスクリーンショットは、コードを実行する前の元のエクセルファイルを示しています。ご覧のとおり、すべてのチャートのタイトルが同じです。
次のスクリーンショットは、コードを実行した後の出力エクセルファイルを示しています。ご覧のとおり、チャートのタイトルがチャートタイプに応じて変更されています。
サンプルコード
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") |
コンソール出力
提供されたソースエクセルファイルで上記のサンプルコードを実行した際のコンソール出力は次のとおりです。
Waterfall
Treemap
Sunburst
Histogram
BoxWhisker