我可以在 Azure 上使用 .NET 运行 IronXL 吗?

This article was translated from English: Does it need improvement?
Translated
View the article in English

是的,IronXL 可以在 Azure 上使用,在 C# 和 VB .NET 应用程序中生成二维码和条形码,还可以从扫描的图像中读取条形码和二维码。

IronXL 已在多个 Azure 平台上进行了全面测试,包括 MVC 网站、Azure Functions 等。


步骤1

1. 安装 IronXL 开始使用

首先使用 NuGet 安装:https://www.nuget.org/packages/IronXL.Excel

Install-Package IronXL.Excel

如何使用教程

2. 性能和Azure层级

我们认为 Azure B1托管级别非常适合我们最终用户的图书馆需求。 如果他们要构建一个高吞吐量系统,那么可能需要升级该系统。

3. 框架选择

我们发现 IronXL 的核心版和框架版在 Azure 上都能正常运行。 .NET Standard 应用程序在速度和稳定性方面似乎略有性能优势,但进程内会占用更多内存。

Azure 免费托管速度慢

Azure 免费层和共享层以及消费计划不适合 QR 处理。 我们推荐 Azure B1 托管/高级计划,这是我们自己使用的。

4. Azure上的Docker

控制 Azure 性能的一种方法是使用 Docker 容器内的 IronXL 应用程序和函数。

我们有针对 Linux 和 Windows 实例的IronXL Azure Docker 全面教程,建议您阅读。

5. 官方Azure Function支持

IronXL 支持 Azure Functions(Azure Functions V3)。 目前还没有用 V4 进行过测试,但它已经在我们的计划之中。

工作中的Azure Function代码示例

在Azure Functions v3.3.1.0+上测试。 以下是一个示例代码:

using System.Net;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using IronXL;
using System.Net.Http.Headers;

// This is an Azure Function that processes an HTTP request and returns an Excel file
[FunctionName("excel")]
public static HttpResponseMessage Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
    ILogger log)
{
    // Log the processing of the request
    log.LogInformation("C# HTTP trigger function processed a request.");

    // Set the IronXL license key
    IronXL.License.LicenseKey = "Key";

    // Load an existing workbook
    var workBook = WorkBook.Load("test-wb.xlsx");

    // Create a response with the workbook content as an attachment
    var result = new HttpResponseMessage(HttpStatusCode.OK);
    result.Content = new ByteArrayContent(workBook.ToByteArray());
    result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
    { 
        FileName = $"{DateTime.Now:yyyyMMddmm}.xlsx" 
    };
    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

    // Return the response
    return result;
}
using System.Net;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using IronXL;
using System.Net.Http.Headers;

// This is an Azure Function that processes an HTTP request and returns an Excel file
[FunctionName("excel")]
public static HttpResponseMessage Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
    ILogger log)
{
    // Log the processing of the request
    log.LogInformation("C# HTTP trigger function processed a request.");

    // Set the IronXL license key
    IronXL.License.LicenseKey = "Key";

    // Load an existing workbook
    var workBook = WorkBook.Load("test-wb.xlsx");

    // Create a response with the workbook content as an attachment
    var result = new HttpResponseMessage(HttpStatusCode.OK);
    result.Content = new ByteArrayContent(workBook.ToByteArray());
    result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
    { 
        FileName = $"{DateTime.Now:yyyyMMddmm}.xlsx" 
    };
    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");

    // Return the response
    return result;
}
Imports System.Net
Imports Microsoft.Azure.WebJobs
Imports Microsoft.Azure.WebJobs.Extensions.Http
Imports Microsoft.AspNetCore.Http
Imports Microsoft.Extensions.Logging
Imports IronXL
Imports System.Net.Http.Headers

' This is an Azure Function that processes an HTTP request and returns an Excel file
<FunctionName("excel")>
Public Shared Function Run(<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route := Nothing)> ByVal req As HttpRequest, ByVal log As ILogger) As HttpResponseMessage
	' Log the processing of the request
	log.LogInformation("C# HTTP trigger function processed a request.")

	' Set the IronXL license key
	IronXL.License.LicenseKey = "Key"

	' Load an existing workbook
	Dim workBook = WorkBook.Load("test-wb.xlsx")

	' Create a response with the workbook content as an attachment
	Dim result = New HttpResponseMessage(HttpStatusCode.OK)
	result.Content = New ByteArrayContent(workBook.ToByteArray())
	result.Content.Headers.ContentDisposition = New ContentDispositionHeaderValue("attachment") With {.FileName = $"{DateTime.Now:yyyyMMddmm}.xlsx"}
	result.Content.Headers.ContentType = New MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

	' Return the response
	Return result
End Function
$vbLabelText   $csharpLabel

常见问题解答

我如何在 Azure 上运行 .NET 应用程序?

您可以使用 IronXL 在 Azure 上运行 .NET 应用程序。它允许在 C# 和 VB .NET 应用程序中生成 QR 和条形码,并从扫描图像中读取。它已在各种 Azure 平台上进行测试,包括 MVC 网站和 Azure 功能。

最佳性能的 Azure 托管级别建议是什么?

对于 IronXL 的最佳性能,我们建议使用 Azure B1 托管级别。如果您正在设计高吞吐量系统,请考虑升级到更高层级。

哪个 .NET 框架在 Azure 上运行效果最好?

IronXL 可在 Azure 上的 .NET Core 和 .NET Framework 上运行。然而,.NET Standard 应用程序在速度和稳定性方面提供了略微的性能优势,但同时内存使用增加。

Azure 的免费层足以进行 QR 处理吗?

对使用 IronXL 进行 QR 处理而言,Azure 的免费和共享层以及消费计划均不建议。我们建议使用 Azure B1 托管或高级计划来获得更好的性能。

可以使用 Docker 管理 Azure 上的 IronXL 应用程序吗?

是的,您可以使用 Docker 来管理 Azure 上的 IronXL 应用程序和功能。该设置允许更好地控制性能。提供了适用于 Linux 和 Windows 实例的详细 Azure Docker 教程。

IronXL 是否支持 Azure Functions?

是的,IronXL 支持 Azure Functions V3。关于 Azure Functions V4 的测试正在进行中,计划在未来扩展支持。

如何在 Azure 上安装 IronXL?

您可以使用以下命令通过 NuGet 安装 IronXL:nuget install IronXL.Excel

有使用 IronXL 与 Azure Functions 的示例吗?

有,文章提供了一个示例 Azure Function 代码处理 HTTP 请求并返回 Excel 文件。该示例经过测试,适用于 Azure Functions v3.3.1.0+。

Curtis Chau
技术作家

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

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

准备开始了吗?
Nuget 下载 1,738,553 | Version: 2025.11 刚刚发布