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