当前位置: 首页 > news >正文

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.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 凭借其强大的功能和灵活性简化了这一过程。

相关文章:

  • 接地电阻柜安装后测试、验收与维护
  • SpringBoot+MySQL家政服务平台 设计开发
  • Imprompter: Tricking LLM Agents into Improper Tool Use
  • Blazor-表单提交的艺术:如何优雅地实现 (下)
  • 打卡day46
  • 界面开发框架DevExpress XAF实践:集成.NET Aspire后如何实现数据库依赖?
  • NoSQL之redis哨兵
  • 洞悉 MySQL 查询性能:EXPLAIN 命令 type 字段详解
  • 【各种主流消息队列(MQ)对比指南】
  • MySQL 事务详解
  • 优选算法第十二讲:队列 + 宽搜 优先级队列
  • 2025年多层PCB技术发展与厂商实践指南
  • 基于深度学习的无人机轨迹预测
  • 嵌入式学习笔记 - FreeRTOS 信号量以及释放函数
  • N2语法 列挙、話題提出
  • 构建 MCP 服务器:第 3 部分 — 添加提示
  • AWS API Gateway配置日志
  • 第16届蓝桥杯青少Scratch 4月stema——飞翔的小燕子
  • Linux中shell编程表达式和数组讲解
  • 使用UDP连接ssh
  • 济南哪里有做网站的公司/网络平台建设及运营方案
  • 厦门网站建设公司怎么选/天津建站网
  • 两女互舔互做日美网站/微信引流获客软件
  • 深圳松岗 网站建设/天津关键词优化专家
  • 《动态网站建设》第03章在线测试/利于seo的建站系统有哪些
  • 父亲节网页制作素材/网站seo收录工具