跳至页脚内容
使用 IRONXL

使用IronXL将 C# 中的 DataGridView 导出到 Excel

使用 IronXL 将 DataGridView 数据导出到 Excel,C# 消除了对 Microsoft Office 的依赖,并提供了容器友好的部署。 创建 WorkBook,遍历 DataGridView 单元格,并以具有完整格式支持的 XLSX 格式保存。

将 Windows Forms 中的数据导出到 Excel 是商业应用程序中的常见需求。 无论是生成报告、创建数据备份,还是与利益相关者共享信息,开发人员都需要一种可靠的方法将 GridView 数据导出为 Excel 格式。 传统上,使用 Microsoft Office Interop 的方法虽能满足这一需求,但其部署复杂且存在依赖性要求,这可能会增加应用程序分发的难度。

本教程演示了一个实用的 C# 示例,使用IronXL (一个 .NET 库,无需安装 Microsoft Office)将 DataGridView 数据导出到 Excel。 您将探索如何实现一个简洁高效的导出解决方案,使其能够在包括云平台和容器在内的不同环境中运行。 无论是部署到 Azure 还是在 Docker 容器中运行应用程序,IronXL 都能为 DevOps 团队提供所需的部署灵活性。

IronXL 主页展示了无需 Microsoft Office 或 Excel Interop 即可读取 Excel 文件的 C# 代码示例,并具有语法高亮显示和 NuGet 下载统计信息。

为什么导出到 Excel 至关重要?

DataGridView 控件是 Windows Forms 应用程序的基础,用于显示用户每天与之交互的表格数据。 将这些数据导出到 Excel,用户便可以利用 Excel 强大的分析工具进行数据分析、制作演示文稿,并与无法访问该应用程序的同事共享数据。 此 C# Excel 导出功能对于业务报告和数据分析工作流至关重要。

使用Microsoft.Office.Interop.Excel传统导出方法需要在运行该应用程序的每台计算机上安装 Excel。 这在服务器环境中或将应用程序分发给没有 Office 许可证的用户时会带来部署挑战。 此外,Interop 方法可能会遇到内存泄漏和 COM 对象清理问题,如果没有小心处理。 在部署至 AWS Lambda 或其他无法安装 Office 的无服务器平台时,这些挑战尤为突出。

现代 .NET 应用程序需要灵活解决方案。 IronXL 通过提供一个无需依赖 Microsoft Office 即可生成 Excel 文件的独立库,解决了这些难题。 这种方法确保了开发、测试和生产环境中的功能一致性,同时支持部署到容器和云平台。

! 跨平台支持图,展示了 .NET 在多个版本(9、8、7、6、Core、Standard、Framework)中的兼容性,并带有 Windows、Linux、Mac、Docker、Azure 和 AWS 等各种平台的图标。

IronXL 与 Interop 相比如何?

下表总结了 IronXL 与 Microsoft Office Interop 在 Excel 导出场景中的主要区别:

IronXL 与 Microsoft Office Interop 在 Excel 导出功能上的对比
特征 IronXL Microsoft Interop
需要安装办公软件
Linux / Docker 支持
COM 对象清理 无需 手动、易出错
内存泄漏风险 低的 若无其他要求,则优先级为高
云/无服务器部署 支持 不支持
导出格式(XLSX、CSV、JSON、XML) 所有支持的 数量有限

如何在 C# 项目中安装 IronXL?

在 Visual Studio 中打开"包管理器控制台"并运行以下命令,或使用 .NET CLI:

Install-Package IronXL
dotnet add package IronXL
Install-Package IronXL
dotnet add package IronXL
SHELL

终端输出显示 IronXL.Excel NuGet 包及其依赖项已成功安装到 C# 项目中

有关详细的安装选项,请参阅 IronXL NuGet 安装指南,或直接在 NuGet.org 上搜索该软件包。 安装完成后,将 using IronXL; 添加到您的 C# 项目文件中,即可访问该库的 Excel 导出功能。 在部署到生产环境时,请应用您的许可证密钥以启用所有功能。 您可以在购买前获取免费试用许可证,以评估 IronXL。

基本 DataGridView 导出结果是什么样子的?

以下代码创建了一个示例 Windows 窗体应用程序,其中包含填充的数据,然后使用 IronXL 顶级语句将其导出到 Excel:

using IronXL;
using System.Data;
using System.Windows.Forms;

// Create a DataTable with sample product data
var dt = new DataTable();
dt.Columns.Add("Product ID", typeof(int));
dt.Columns.Add("Product Name", typeof(string));
dt.Columns.Add("Category", typeof(string));
dt.Columns.Add("Price", typeof(decimal));
dt.Columns.Add("Stock", typeof(int));

dt.Rows.Add(1001, "Laptop Pro", "Electronics", 1299.99m, 15);
dt.Rows.Add(1002, "Wireless Mouse", "Accessories", 29.99m, 50);
dt.Rows.Add(1003, "USB-C Cable", "Accessories", 19.99m, 100);
dt.Rows.Add(1004, "Monitor 27\"", "Electronics", 399.99m, 8);
dt.Rows.Add(1005, "Keyboard Mechanical", "Accessories", 89.99m, 25);

// Bind to DataGridView
var dataGridView1 = new DataGridView();
dataGridView1.DataSource = dt;

// Create new Excel workbook
var workbook = WorkBook.Create(ExcelFileFormat.XLSX);
var worksheet = workbook.DefaultWorkSheet;

// Export column headers
for (int colIndex = 0; colIndex < dataGridView1.Columns.Count; colIndex++)
{
    worksheet.SetCellValue(0, colIndex, dataGridView1.Columns[colIndex].HeaderText);
}

// Export data rows
for (int rowIndex = 0; rowIndex < dataGridView1.Rows.Count; rowIndex++)
{
    if (!dataGridView1.Rows[rowIndex].IsNewRow)
    {
        for (int colIndex = 0; colIndex < dataGridView1.Columns.Count; colIndex++)
        {
            var cellValue = dataGridView1.Rows[rowIndex].Cells[colIndex].Value;
            if (cellValue is decimal or double or int)
                worksheet.SetCellValue(rowIndex + 1, colIndex, Convert.ToDouble(cellValue));
            else
                worksheet.SetCellValue(rowIndex + 1, colIndex, cellValue?.ToString() ?? string.Empty);
        }
    }
}

// Save the Excel file
workbook.SaveAs("DataGridViewExport.xlsx");
Console.WriteLine("Export completed successfully!");
using IronXL;
using System.Data;
using System.Windows.Forms;

// Create a DataTable with sample product data
var dt = new DataTable();
dt.Columns.Add("Product ID", typeof(int));
dt.Columns.Add("Product Name", typeof(string));
dt.Columns.Add("Category", typeof(string));
dt.Columns.Add("Price", typeof(decimal));
dt.Columns.Add("Stock", typeof(int));

dt.Rows.Add(1001, "Laptop Pro", "Electronics", 1299.99m, 15);
dt.Rows.Add(1002, "Wireless Mouse", "Accessories", 29.99m, 50);
dt.Rows.Add(1003, "USB-C Cable", "Accessories", 19.99m, 100);
dt.Rows.Add(1004, "Monitor 27\"", "Electronics", 399.99m, 8);
dt.Rows.Add(1005, "Keyboard Mechanical", "Accessories", 89.99m, 25);

// Bind to DataGridView
var dataGridView1 = new DataGridView();
dataGridView1.DataSource = dt;

// Create new Excel workbook
var workbook = WorkBook.Create(ExcelFileFormat.XLSX);
var worksheet = workbook.DefaultWorkSheet;

// Export column headers
for (int colIndex = 0; colIndex < dataGridView1.Columns.Count; colIndex++)
{
    worksheet.SetCellValue(0, colIndex, dataGridView1.Columns[colIndex].HeaderText);
}

// Export data rows
for (int rowIndex = 0; rowIndex < dataGridView1.Rows.Count; rowIndex++)
{
    if (!dataGridView1.Rows[rowIndex].IsNewRow)
    {
        for (int colIndex = 0; colIndex < dataGridView1.Columns.Count; colIndex++)
        {
            var cellValue = dataGridView1.Rows[rowIndex].Cells[colIndex].Value;
            if (cellValue is decimal or double or int)
                worksheet.SetCellValue(rowIndex + 1, colIndex, Convert.ToDouble(cellValue));
            else
                worksheet.SetCellValue(rowIndex + 1, colIndex, cellValue?.ToString() ?? string.Empty);
        }
    }
}

// Save the Excel file
workbook.SaveAs("DataGridViewExport.xlsx");
Console.WriteLine("Export completed successfully!");
Imports IronXL
Imports System.Data
Imports System.Windows.Forms

' Create a DataTable with sample product data
Dim dt As New DataTable()
dt.Columns.Add("Product ID", GetType(Integer))
dt.Columns.Add("Product Name", GetType(String))
dt.Columns.Add("Category", GetType(String))
dt.Columns.Add("Price", GetType(Decimal))
dt.Columns.Add("Stock", GetType(Integer))

dt.Rows.Add(1001, "Laptop Pro", "Electronics", 1299.99D, 15)
dt.Rows.Add(1002, "Wireless Mouse", "Accessories", 29.99D, 50)
dt.Rows.Add(1003, "USB-C Cable", "Accessories", 19.99D, 100)
dt.Rows.Add(1004, "Monitor 27""", "Electronics", 399.99D, 8)
dt.Rows.Add(1005, "Keyboard Mechanical", "Accessories", 89.99D, 25)

' Bind to DataGridView
Dim dataGridView1 As New DataGridView()
dataGridView1.DataSource = dt

' Create new Excel workbook
Dim workbook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
Dim worksheet As WorkSheet = workbook.DefaultWorkSheet

' Export column headers
For colIndex As Integer = 0 To dataGridView1.Columns.Count - 1
    worksheet.SetCellValue(0, colIndex, dataGridView1.Columns(colIndex).HeaderText)
Next

' Export data rows
For rowIndex As Integer = 0 To dataGridView1.Rows.Count - 1
    If Not dataGridView1.Rows(rowIndex).IsNewRow Then
        For colIndex As Integer = 0 To dataGridView1.Columns.Count - 1
            Dim cellValue = dataGridView1.Rows(rowIndex).Cells(colIndex).Value
            If TypeOf cellValue Is Decimal OrElse TypeOf cellValue Is Double OrElse TypeOf cellValue Is Integer Then
                worksheet.SetCellValue(rowIndex + 1, colIndex, Convert.ToDouble(cellValue))
            Else
                worksheet.SetCellValue(rowIndex + 1, colIndex, If(cellValue?.ToString(), String.Empty))
            End If
        Next
    End If
Next

' Save the Excel file
workbook.SaveAs("DataGridViewExport.xlsx")
Console.WriteLine("Export completed successfully!")
$vbLabelText   $csharpLabel

这段代码展示了核心的导出功能。 DataTable 设置使用示例产品数据填充网格,作为 DataGridView 控件的通用数据源。 在处理大型数据集时,建议使用 IronXL 的 DataSet 导入和导出功能以提升性能。

导出循环遍历 DataGridView,使用 SetCellValue 和行和列索引将标题和数据放入 Excel 单元格中。 IronXL 文档还介绍了适用于更复杂场景的其他单元格写入选项。 IsNewRow 检查会跳过可编辑的 DataGridViews 底部的空行,从而确保 Excel 输出干净,不会出现意外的空白行。

Windows Forms 应用程序显示一个 DataGridView,其中填充了产品数据,包括产品 ID、名称、类别、价格和库存列,下方有一个"导出到 Excel"按钮。

Microsoft Excel 电子表格,显示导出的产品数据,包含产品 ID、产品名称、类别、价格和库存水平等列,涵盖电子产品和电脑配件。

如果您在基于 Web 的 ASP.NET MVC 应用程序中实现此功能,请通过使用 Content-Disposition HTTP 标头将文件作为可下载的响应返回来扩展该方法。 对于 ASP.NET WebForms 开发人员,导出控件时可能需要重写 VerifyRenderingInServerForm 以确保正确呈现。 请访问 IronXL 功能页面,查看支持场景的完整列表。

如何为 Excel 导出文件添加 Professional 格式?

专业的 Excel 导出通常需要格式化以提高可读性。 IronXL 提供了样式设置功能,包括字体自定义、背景颜色、边框和对齐方式。 下面的示例添加了标题格式和交替行颜色:

using IronXL;
using System.Data;
using System.Windows.Forms;

// Assume dataGridView1 is already populated with data
var dataGridView1 = new DataGridView();

// (populate dataGridView1 with data as shown in the previous example)

var workbook = WorkBook.Create(ExcelFileFormat.XLSX);
var worksheet = workbook.DefaultWorkSheet;

// Set column headers with formatting
for (int colIndex = 0; colIndex < dataGridView1.Columns.Count; colIndex++)
{
    var headerCell = worksheet.GetCellAt(0, colIndex);
    headerCell.Value = dataGridView1.Columns[colIndex].HeaderText;
    headerCell.Style.Font.Bold = true;
    headerCell.Style.BackgroundColor = "#4472C4";
    headerCell.Style.Font.Color = "#FFFFFF";
    headerCell.Style.HorizontalAlignment = IronXL.Styles.HorizontalAlignment.Center;
}

// Export data with alternating row colors
for (int rowIndex = 0; rowIndex < dataGridView1.Rows.Count; rowIndex++)
{
    if (!dataGridView1.Rows[rowIndex].IsNewRow)
    {
        for (int colIndex = 0; colIndex < dataGridView1.Columns.Count; colIndex++)
        {
            var cellValue = dataGridView1.Rows[rowIndex].Cells[colIndex].Value;
            var excelCell = worksheet.GetCellAt(rowIndex + 1, colIndex);

            if (cellValue != null)
                excelCell.Value = cellValue.ToString();

            // Apply alternating row background
            if (rowIndex % 2 == 0)
                excelCell.Style.BackgroundColor = "#F2F2F2";
        }
    }
}

// Auto-fit columns
for (int colIndex = 0; colIndex < dataGridView1.Columns.Count; colIndex++)
{
    worksheet.AutoSizeColumn(colIndex);
}

workbook.SaveAs("FormattedExport.xlsx");
Console.WriteLine("Formatted export completed successfully!");
using IronXL;
using System.Data;
using System.Windows.Forms;

// Assume dataGridView1 is already populated with data
var dataGridView1 = new DataGridView();

// (populate dataGridView1 with data as shown in the previous example)

var workbook = WorkBook.Create(ExcelFileFormat.XLSX);
var worksheet = workbook.DefaultWorkSheet;

// Set column headers with formatting
for (int colIndex = 0; colIndex < dataGridView1.Columns.Count; colIndex++)
{
    var headerCell = worksheet.GetCellAt(0, colIndex);
    headerCell.Value = dataGridView1.Columns[colIndex].HeaderText;
    headerCell.Style.Font.Bold = true;
    headerCell.Style.BackgroundColor = "#4472C4";
    headerCell.Style.Font.Color = "#FFFFFF";
    headerCell.Style.HorizontalAlignment = IronXL.Styles.HorizontalAlignment.Center;
}

// Export data with alternating row colors
for (int rowIndex = 0; rowIndex < dataGridView1.Rows.Count; rowIndex++)
{
    if (!dataGridView1.Rows[rowIndex].IsNewRow)
    {
        for (int colIndex = 0; colIndex < dataGridView1.Columns.Count; colIndex++)
        {
            var cellValue = dataGridView1.Rows[rowIndex].Cells[colIndex].Value;
            var excelCell = worksheet.GetCellAt(rowIndex + 1, colIndex);

            if (cellValue != null)
                excelCell.Value = cellValue.ToString();

            // Apply alternating row background
            if (rowIndex % 2 == 0)
                excelCell.Style.BackgroundColor = "#F2F2F2";
        }
    }
}

// Auto-fit columns
for (int colIndex = 0; colIndex < dataGridView1.Columns.Count; colIndex++)
{
    worksheet.AutoSizeColumn(colIndex);
}

workbook.SaveAs("FormattedExport.xlsx");
Console.WriteLine("Formatted export completed successfully!");
Imports IronXL
Imports System.Data
Imports System.Windows.Forms

' Assume dataGridView1 is already populated with data
Dim dataGridView1 As New DataGridView()

' (populate dataGridView1 with data as shown in the previous example)

Dim workbook = WorkBook.Create(ExcelFileFormat.XLSX)
Dim worksheet = workbook.DefaultWorkSheet

' Set column headers with formatting
For colIndex As Integer = 0 To dataGridView1.Columns.Count - 1
    Dim headerCell = worksheet.GetCellAt(0, colIndex)
    headerCell.Value = dataGridView1.Columns(colIndex).HeaderText
    headerCell.Style.Font.Bold = True
    headerCell.Style.BackgroundColor = "#4472C4"
    headerCell.Style.Font.Color = "#FFFFFF"
    headerCell.Style.HorizontalAlignment = IronXL.Styles.HorizontalAlignment.Center
Next

' Export data with alternating row colors
For rowIndex As Integer = 0 To dataGridView1.Rows.Count - 1
    If Not dataGridView1.Rows(rowIndex).IsNewRow Then
        For colIndex As Integer = 0 To dataGridView1.Columns.Count - 1
            Dim cellValue = dataGridView1.Rows(rowIndex).Cells(colIndex).Value
            Dim excelCell = worksheet.GetCellAt(rowIndex + 1, colIndex)

            If cellValue IsNot Nothing Then
                excelCell.Value = cellValue.ToString()
            End If

            ' Apply alternating row background
            If rowIndex Mod 2 = 0 Then
                excelCell.Style.BackgroundColor = "#F2F2F2"
            End If
        Next
    End If
Next

' Auto-fit columns
For colIndex As Integer = 0 To dataGridView1.Columns.Count - 1
    worksheet.AutoSizeColumn(colIndex)
Next

workbook.SaveAs("FormattedExport.xlsx")
Console.WriteLine("Formatted export completed successfully!")
$vbLabelText   $csharpLabel

此增强版对导出的 Excel 文件采用了 Professional 格式设置。标题采用加粗文本,配以蓝色背景和白色字体,与数据行形成清晰的视觉区分。 该代码通过模运算实现行交替着色,从而提高了大型数据集的可读性。 您可以参考 IronXL 单元格格式指南进一步自定义外观,或使用合并单元格功能来跨列显示标题。

AutoSizeColumn 方法会调整列宽以适应内容,从而避免导出后手动调整。 这些格式化选项将基本的数据导出转变为可以立即分享给用户的演示文档。 请参阅《如何使用 IronXL 写入 Excel 文件》以了解更多的格式设置和数据写入模式。

如何导出为多种格式并添加公式?

IronXL 不仅支持基本的 Excel 导出功能,还提供了公式支持、多工作表以及多种输出格式等特性。 以下示例展示了这些功能:

using IronXL;

var workbook = WorkBook.Create(ExcelFileFormat.XLSX);
var worksheet = workbook.DefaultWorkSheet;

// (populate worksheet with DataGridView data as shown above)
int dataRowCount = 5; // Replace with actual dataGridView1.Rows.Count

// Add a SUM formula to calculate the total price column
worksheet.SetCellValue(dataRowCount + 2, 3, $"=SUM(D2:D{dataRowCount + 1})");

// Create a summary worksheet
var summarySheet = workbook.CreateWorkSheet("Summary");
summarySheet.SetCellValue(0, 0, "Total Products");
summarySheet.SetCellValue(0, 1, dataRowCount);

// Save in multiple formats
workbook.SaveAs("export.xlsx");
workbook.SaveAsCsv("export.csv");
workbook.SaveAsJson("export.json");
workbook.SaveAsXml("export.xml");

Console.WriteLine("Multi-format export completed!");
using IronXL;

var workbook = WorkBook.Create(ExcelFileFormat.XLSX);
var worksheet = workbook.DefaultWorkSheet;

// (populate worksheet with DataGridView data as shown above)
int dataRowCount = 5; // Replace with actual dataGridView1.Rows.Count

// Add a SUM formula to calculate the total price column
worksheet.SetCellValue(dataRowCount + 2, 3, $"=SUM(D2:D{dataRowCount + 1})");

// Create a summary worksheet
var summarySheet = workbook.CreateWorkSheet("Summary");
summarySheet.SetCellValue(0, 0, "Total Products");
summarySheet.SetCellValue(0, 1, dataRowCount);

// Save in multiple formats
workbook.SaveAs("export.xlsx");
workbook.SaveAsCsv("export.csv");
workbook.SaveAsJson("export.json");
workbook.SaveAsXml("export.xml");

Console.WriteLine("Multi-format export completed!");
Imports IronXL

Dim workbook = WorkBook.Create(ExcelFileFormat.XLSX)
Dim worksheet = workbook.DefaultWorkSheet

' (populate worksheet with DataGridView data as shown above)
Dim dataRowCount As Integer = 5 ' Replace with actual dataGridView1.Rows.Count

' Add a SUM formula to calculate the total price column
worksheet.SetCellValue(dataRowCount + 2, 3, $"=SUM(D2:D{dataRowCount + 1})")

' Create a summary worksheet
Dim summarySheet = workbook.CreateWorkSheet("Summary")
summarySheet.SetCellValue(0, 0, "Total Products")
summarySheet.SetCellValue(0, 1, dataRowCount)

' Save in multiple formats
workbook.SaveAs("export.xlsx")
workbook.SaveAsCsv("export.csv")
workbook.SaveAsJson("export.json")
workbook.SaveAsXml("export.xml")

Console.WriteLine("Multi-format export completed!")
$vbLabelText   $csharpLabel

IronXL 支持 Excel 公式,允许您直接在导出的文件中添加计算。 上面的示例添加了一个公式,用于自动计算列总计。 创建多个工作表有助于组织复杂的导出,例如将详细数据与摘要信息分开。 请访问 IronXL 创建 Excel 文件的操作指南,了解更多的工作表管理模式。

其格式灵活性在集成场景中尤为重要。 虽然 XLSX 是 Excel 文件的标准格式,但 CSV 导出能与数据库系统及旧版应用程序实现广泛兼容。 JSON 和 XML 格式有助于与 Web 服务和 API 进行数据交换。您还可以打开现有工作簿,将导出的数据追加到现有电子表格中,而无需每次都创建新文件。

不同导出格式有何区别?

! Excel 电子表格显示产品库存,包含产品 ID、名称、类别、价格和库存列,求和公式结果为 1839.95,显示在单元格 D9 中。

! Excel 电子表格显示了一个"汇总"工作表,其中 A1 和 B1 单元格中显示"产品总数:5",演示了将 DataGridView 数据导出到 Excel 并生成多个工作表的结果。

! Excel 电子表格显示产品库存数据,列包括产品 ID、产品名称、类别、价格和库存数量,单元格 D9 中显示总和为 1839.95。

! JSON 文件,以代码编辑器界面显示产品数据,包含产品 ID、名称、类别、价格和库存字段。

! XML 文件显示导出的 DataGridView 数据,其中包含产品信息,包括 ID、名称、类别、价格和库存水平,并按 Sheet 元素进行组织。

IronXL 如何简化您的 C# 开发工作流?

IronXL 的主要优势在于消除了对 Microsoft Office 的依赖。 无论部署在开发工作站、客户机器还是 Docker 容器中,您的应用程序都能保持稳定运行。 这种独立性简化了部署并减少了与 Office 版本和安装相关的支持问题。 微软的 Open XML SDK 是另一种无需 Office 的替代方案,但与 IronXL 的高级 API 相比,它需要编写大量冗余代码。 关于跨平台 .NET 10 开发指南,Microsoft .NET 文档涵盖了平台目标、部署模型以及 Windows Forms 的具体细节。

该库的 API 设计优先考虑简单性。 与 Interop 基于 COM 的方法(需要仔细处理对象释放)不同,IronXL 采用标准 .NET 模式,这对 C# 开发人员而言非常自然。 跨平台支持意味着为 Windows Forms 构建的导出功能可在运行于 Linux 服务器的 ASP.NET Core 应用程序中复用。 如需了解完整功能概览,请访问 IronXL 功能页面

您还可以从 Excel 导入数据,以便在导出之前预先填充您的 DataGridView,从而创建往返工作流程,用户可以加载 Excel 数据,在网格中编辑数据,然后将结果导出回 Excel。 《Excel 文件读取指南》详细介绍了导入相关的内容。

在处理敏感数据时,IronXL 支持工作簿级和工作表级的密码保护。 IronXL 文档涵盖了在分发前必须保护导出文件的安全选项。

! Excel 库的功能概述,显示六个主要类别:创建、保存和导出、编辑工作簿、处理数据、保护工作簿和编辑布局选项。

生产环境使用的许可选项有哪些?

IronXL 在生产环境中部署时需要有效的许可证密钥。 您可以先申请免费试用许可证,解锁所有功能进行评估。 请查阅 IronXL 许可页面,了解从单开发者许可到 Unlimited Enterprise 部署等所有许可层级的详细信息。

在使用任何 IronXL 功能之前,请在您的应用程序中应用许可证密钥:

IronXL.License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
IronXL.License.LicenseKey = "YOUR-LICENSE-KEY-HERE";
Imports IronXL

IronXL.License.LicenseKey = "YOUR-LICENSE-KEY-HERE"
$vbLabelText   $csharpLabel

这一行代码将使该库在应用程序进程的整个生命周期内保持激活状态。 对于 Web 应用程序和服务,请在启动时设置许可证密钥,以便所有请求都能享受完整功能集,且不显示水印。

IronXL 的许可选项分为四个级别:Lite(749 美元)、Plus(999 美元)、Professional(1,999 美元)和 Unlimited(3,999 美元),每个级别对开发者、地点和项目数量都有不同的限制。

为何应选择 IronXL 进行 C# 中的 Excel 导出?

使用 IronXL 将 DataGridView 数据导出到 Excel 变得非常简单。 该库消除了传统 Interop 的复杂性,同时提供专业的格式化功能和多种导出格式。 其容器友好型架构、极少的依赖项以及跨平台支持,使其成为现代 DevOps 工作流的理想选择。

IronXL首页是探索完整库功能的起点。 无论是构建微服务、部署到 Kubernetes 集群,还是运行无服务器函数,IronXL 都能无缝集成到 CI/CD 管道中。 Excel 导出操作指南提供了适用于不同导出场景的额外示例,而打开工作簿指南则涵盖了读取和修改现有文件的内容。

立即获取免费试用许可证,探索完整功能集。 IronXL 的教程和代码示例可帮助您快速实现可投入生产的解决方案。 您可以根据部署需求,从个人开发者许可证到Unlimited Enterprise部署,灵活选择适合的许可方案。 如需了解入门指南,IronXL 文档中心提供了 API 参考、代码示例和故障排除指南。

常见问题解答

使用 IronXL 将 DataGridView 导出到 Excel 的好处是什么?

IronXL 通过消除对 Microsoft Office Interop 的需求,简化 DataGridView 内容导出到 Excel 的过程,减少了部署复杂性,并删除了依赖要求。

IronXL 如何改善应用程序分发?

IronXL 通过不要求 Microsoft Office Interop 减少了应用程序分发的复杂性,后者经常伴随有复杂部署的额外依赖性。

IronXL 能否导出 VB.NET 中的 DataGridView 数据?

是的,IronXL 提供了一种将 DataGridView 数据导出到 VB.NET 中的 Excel 的实用解决方案,使得在业务应用程序中更易于管理数据。

将 DataGridView 导出到 Excel 的常见用例是什么?

常见用例包括生成报告、创建数据备份以及与业务环境中的利益相关者共享信息。

IronXL 是否需要在系统上安装 Microsoft Excel?

不,IronXL 不需要安装 Microsoft Excel,因为它独立于 Excel 运行,简化了部署过程。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

钢铁支援团队

我们每周 5 天,每天 24 小时在线。
聊天
电子邮件
打电话给我