Excel处理控件Aspose.Cells教程:使用 C# 在 Excel 中创建组合图表

翻译|使用教程|编辑:吉炜炜|2025-06-06 10:55:30.843|阅读 42 次

概述:可视化项目时间线对于有效规划和跟踪至关重要。在本篇教程中,您将学习如何使用 C# 在 Excel 中创建组合图,只需几行代码,即可自动生成动态、美观的组合图。

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

相关链接:

可视化项目时间线对于有效规划和跟踪至关重要。在本篇教程中,您将学习如何使用 C# 在 Excel 中创建组合图。只需几行代码,即可自动生成动态、美观的组合图。无论您是在构建项目管理工具还是处理内部报告,本指南都将向您展示如何将任务数据转换为清晰专业的时间线——完全可自定义,并可导出为 Excel、PDF 或图像格式。

Aspose.Cells 最新版下载

使用 C# Excel 库创建组合图表

Aspose.Cells for .NET是一个功能强大的 Excel 库,可简化在 Excel 中创建组合图的过程。它提供了强大的功能,可通过编程方式操作 Excel 文件。借助 Aspose.Cells,开发人员可以轻松创建、修改和自定义图表和图形。该库支持各种 Excel 格式并提供高级功能,是项目经理和开发人员的理想选择。

Aspose.Cells for .NET 因其易于集成和灵活性而脱颖而出。以下是一些主要功能:

  • 全面的 API:访问各种 Excel 功能。
  • 高级定制:定制图表和图形以满足特定需求。
  • 高性能:高效处理大型数据集而不影响速度。
  • 多种格式支持:使用各种 Excel 格式,包括 XLSX、XLS 和 CSV。

按照以下简单步骤开始使用 Aspose.Cells for .NET

  1. 从发布版本中下载该库
  2. 使用以下命令通过 NuGet 包管理器安装它:
PM> Install-Package Aspose.Cells

使用 C# 在 Excel 中创建组合图表

组合图表数据示例

组合图表数据示例

组合图表数据示例

如何创建组合图表

按照以下步骤使用 C# 和 Aspose.Cells for .NET 在 Excel 中创建组合图表:

  1. 使用该类加载现有的 Excel 文件Workbook
  2. 使用 访问第一个工作表workbook.Worksheets[0]
  3. 使用 添加图表ChartType.StockVolumeHighLowClose
  4. 设置样式和Series设置。
  5. 使用 保存工作簿workbook.Save()

以下是实现上述步骤的 C# 代码片段:

// Create the workbook
Workbook workbook = new Workbook("combo.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.Worksheets[0];
// Add a stock vloume(VHLC)
int pieIdx = worksheet.Charts.Add(ChartType.StockVolumeHighLowClose, 15, 0, 34, 12);
// Retrieve the Chart object
Chart chart = worksheet.Charts[pieIdx];
// Set the legend can be showed
chart.ShowLegend = true;
// Set the chart title name 
chart.Title.Text = "Combo Chart";
// Set the Legend at the bottom of the chart area
chart.Legend.Position = LegendPositionType.Bottom;
// Set data range
chart.SetChartDataRange("A1:E12", true);
// Set category data 
chart.NSeries.CategoryData = "A2:A12";
// Set the Series[1] Series[2] and Series[3] to different Marker Style
for (int j = 0; j < chart.NSeries.Count; j++)
{
	switch (j)
	{
		case 1:
			chart.NSeries[j].Marker.MarkerStyle = ChartMarkerType.Circle;
			chart.NSeries[j].Marker.MarkerSize = 15;
			chart.NSeries[j].Marker.Area.Formatting = FormattingType.Custom;
			chart.NSeries[j].Marker.Area.ForegroundColor = Color.Pink;
			chart.NSeries[j].Border.IsVisible = false;
			break;
		case 2:
			chart.NSeries[j].Marker.MarkerStyle = ChartMarkerType.Dash;
			chart.NSeries[j].Marker.MarkerSize = 15;
			chart.NSeries[j].Marker.Area.Formatting = FormattingType.Custom;
			chart.NSeries[j].Marker.Area.ForegroundColor = Color.Orange;
			chart.NSeries[j].Border.IsVisible = false;
			break;
		case 3:
			chart.NSeries[j].Marker.MarkerStyle = ChartMarkerType.Square;
			chart.NSeries[j].Marker.MarkerSize = 15;
			chart.NSeries[j].Marker.Area.Formatting = FormattingType.Custom;
			chart.NSeries[j].Marker.Area.ForegroundColor = Color.LightBlue;
			chart.NSeries[j].Border.IsVisible = false;
			break;
	}
}
// Set the chart type for Series[0] 
chart.NSeries[0].Type = ChartType.Line;
// Set style for the border of first series
chart.NSeries[0].Border.Style = LineType.Solid;
// Set Color for the first series
chart.NSeries[0].Border.Color =  Color.DarkBlue;
// Fill the PlotArea area with nothing 
chart.PlotArea.Area.Formatting = FormattingType.None;
// Save the Excel file
workbook.Save("out.xlsx");
使用 C# 在 Excel 中创建组合图表

使用 C# 在 Excel 中创建组合图表

结论

在本篇博文中,我们探讨了如何使用 C# 在 Excel 中创建组合图。Aspose.Cells for .NET 凭借其强大的功能和灵活性简化了这一过程。

————————————————————————————————————————

关于慧都科技:

慧都科技是一家行业数字化解决方案公司,长期专注于软件、油气与制造行业。公司基于深入的业务理解与管理洞察,以系统化的业务建模驱动技术落地,帮助企业实现智能化运营与长期竞争优势。在软件工程领域,我们提供开发控件、研发管理、代码开发、部署运维等软件开发全链路所需的产品,提供正版授权采购、技术选型、个性化维保等服务,帮助客户实现技术合规、降本增效与风险可控。慧都科技Aspose在中国的官方授权代理商,提供Aspose系列产品免费试用,咨询,正版销售等于一体的专业化服务。Aspose是文档处理领域的优秀产品,帮助企业高效构建文档处理的应用程序。

下载|体验更多Aspose产品联系在线客服咨询,或拨打产品热线:023-68661681

加入Aspose技术交流QQ群(1041253375),与更多小伙伴一起探讨提升开发技能。

aspose下载




标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com

文章转载自:慧都网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP