Aspose.Cells如何在Excel中创建图表并导出图表为图片

作者:控件中国网   出处:控件中国网   2016-12-08 14:22:20   阅读:105

Aspose.Cells是一款功能上跟Microsoft Excel相近的无图形界面类控件,可以通过该控件在开发人员的应用程序中集成Excel文件处理的功能,可以进行Excel文件的创建、编辑、操作和转换。在使用Excel时经常需要对Excel内的数据进行图形化展示,这就需要把一系列数据转换为图表。Aspose.Cells可以快速帮助开发人员在Excel文件内创建各种样式的图表并且还可以把创建好的图表导出为各种格式的图片,具体如何实现该功能可以参考下面的.NET代码:
Workbook workbook = new Workbook();
//Adding a new worksheet to the Excel object
int sheetIndex = workbook.Worksheets.Add();
//Obtaining the reference of the newly added worksheet by
//passing its sheet index
Worksheet worksheet = workbook.Worksheets[sheetIndex];
//Adding a sample value to "A1" cell
worksheet.Cells["A1"].PutValue(50);
//Adding a sample value to "A2" cell
worksheet.Cells["A2"].PutValue(100);
//Adding a sample value to "A3" cell
worksheet.Cells["A3"].PutValue(150);
//Adding a sample value to "B1" cell
worksheet.Cells["B1"].PutValue(4);
//Adding a sample value to "B2" cell
worksheet.Cells["B2"].PutValue(20);
//Adding a sample value to "B3" cell
worksheet.Cells["B3"].PutValue(50);
 
//Adding a chart to the worksheet
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5);
//Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
//Adding Series Collection (chart data source) to the chart ranging from "A1" cell to "B3"
chart.NSeries.Add("A1:B3", true);
//Converting chart to image.
chart.ToImage("d:\\Chart.emf", System.Drawing.Imaging.ImageFormat.Emf);
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat