PNG JPG BMP TIFF XLS
Aspose.Cells  for .NET

将图表转换为 BMP C# 中的图像

本机高性能 XLS 使用服务器端 API 记录图表到图像的转换,无需使用 Microsoft 或 Adobe PDF 等任何软件。

如何使用 C# 将图表转换为 BMP 图像

为了转换 XLSX 图表,我们将使用

Aspose.Cells for .NET

API这是一个功能丰富、强大且易于使用的文档操作API,适用于C#平台。打开

NuGet

包管理器,搜索 Aspose.Cells 并安装。您还可以从包管理器控制台使用以下命令。

命令


PM> Install-Package Aspose.Cells

将图表转换为 C# 中的 BMP 文件的步骤

基本文档图表

Aspose.Cells for .NET

只需几行代码即可完成 API。

创建 XLSX 文件。 获取图表。

  • 将图表转换为 BMP 图像。

系统要求

我们的 API 在所有主要平台和操作系统上均受支持。在执行下面的代码之前,请确保您的系统满足以下先决条件。

  • Microsoft Windows 或具有 .NET Framework、.NET Core、Mono 或 Xamarin 平台的兼容操作系统
  • 开发环境如Microsoft Visual Studio
  • 在项目中添加对 Aspose.Cells for .NET DLL 的引用 - 使用上面的下载按钮从 NuGet 安装
 

将 XLSX 文件图表转换为 BMP 图像 - C#

// Instantiating a Workbook object
Workbook wkb = new Workbook();
// Obtaining the reference of the first worksheet
Worksheet wks = wkb.Worksheets[0];
// Adding sample values to cells
wks.Cells["A2"].PutValue("Category1");
wks.Cells["A3"].PutValue("Category2");
wks.Cells["A4"].PutValue("Category3");
wks.Cells["B1"].PutValue("Column1");
wks.Cells["B2"].PutValue(4);
wks.Cells["B3"].PutValue(20);
wks.Cells["B4"].PutValue(50);
wks.Cells["C1"].PutValue("Column2");
wks.Cells["C2"].PutValue(50);
wks.Cells["C3"].PutValue(100);
wks.Cells["C4"].PutValue(150);
// Adding a chart to the worksheet
int chartIndex = wks.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5);
// Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = wks.Charts[chartIndex];
// Setting chart data source as the range "A1:C4"
chart.SetChartDataRange("A1:C4", true);
// Converting to the BMP file
chart.ToImage("output.bmp");