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

可视化项目时间线对于有效规划和跟踪至关重要。在本篇教程中,您将学习如何使用 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.Worksheets0。
  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 中创建组合图。Aspose.Cells for .NET 凭借其强大的功能和灵活性简化了这一过程。

相关推荐
samble8 小时前
从零搭建灌装监控系统(十):生产追溯,条码触发自动记录
c#·wpf·mvvm·modbus·工业控制
czhc114007566312 小时前
退出防呆:用“总闸“收口所有退出入口,以及三个并发语法坑
开发语言·c#
是枚小菜鸡儿吖15 小时前
TraceBack:基于TextIn xParse,统一解析PDF/Word/Excel/扫描件/截图,自动交叉核验维修报告真伪,带原文出处,让造假无处遁形
pdf·word·excel
淡海水15 小时前
02-01-原理篇-Mark-Sweep与变种算法
算法·unity·c#·游戏引擎·.net·gc
UIU11419 小时前
同一个变量在两个 .c 文件里类型不一致,程序会怎样?
c++·学习·c#
波力海苔夹心脆6751 天前
C# 值类型与引用类型详解:存储位置、赋值机制、参数传递、相等比较、装箱拆箱与常见陷阱
开发语言·jvm·经验分享·笔记·c#·.net
估值探索者1 天前
【Python量化策略实战 #02】多因子合成mom和vol两因子打分合成
开发语言·c++·python·数据挖掘·c#
gudufy2 天前
EasyAdminBlazor Excel 导入源码解析:数据验证、权限与事务如何处理?
excel·blazor·admin
copilot中国版2 天前
Copilot + Excel鱼骨图:让根因分析从“凭经验”变成“有依据”
人工智能·excel·copilot
泡海椒2 天前
JQuick-Excel 字段映射实战:用 MAPPING 固化 Excel 表头与业务字段契约
xml·java·开发语言·excel