如何在 Azure 上使用 .NET 运行 IronXL?

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

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

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


步骤 1

1.安装 IronXL 以开始使用

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

Install-Package IronXL.Excel

教程

2.性能和 Azure 层级

我们建议 Azure B1 托管级别非常适合最终用户的图书馆需求。如果他们正在创建一个高吞吐量系统,则可能需要升级。

3.框架选择

我们发现,IronXL for Core 和 for Framework 都能在 Azure 上运行。.NET Standard 应用程序在速度和稳定性方面似乎略胜一筹,但在运行过程中会占用更多内存。

Azure 免费层托管速度慢

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

4.Azure 上的 Docker

在 Azure 上获得控制性能能力的一种方法是在 Docker 容器中使用 IronXL 应用程序和函数。

我们有一个全面的 IronXL Azure Docker 教程 Linux 和 Windows 实例,推荐阅读。

5.官方 Azure 功能支持

IronXL 支持 Azure 功能 (Azure 函数 V3).到目前为止,我们还没有对 V4 进行过测试,但它已在我们的队列中。

工作中的 Azure 函数代码示例

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

    [FunctionName("barcode")]
    public static HttpResponseMessage Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
        IronXL.License.LicenseKey = "Key";
        var MyBarCode = BarcodeWriter.CreateBarcode("IronXL Test", BarcodeEncoding.QRCode);
        var result = new HttpResponseMessage(HttpStatusCode.OK);
        result.Content = new ByteArrayContent(MyBarCode.ToJpegBinaryData());
        result.Content.Headers.ContentDisposition =
                new ContentDispositionHeaderValue("attachment") { FileName = $"{DateTime.Now.ToString("yyyyMMddmm")}.jpg" };
        result.Content.Headers.ContentType =
                new MediaTypeHeaderValue("image/jpeg");
        return result;
    }
    [FunctionName("barcode")]
    public static HttpResponseMessage Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
        IronXL.License.LicenseKey = "Key";
        var MyBarCode = BarcodeWriter.CreateBarcode("IronXL Test", BarcodeEncoding.QRCode);
        var result = new HttpResponseMessage(HttpStatusCode.OK);
        result.Content = new ByteArrayContent(MyBarCode.ToJpegBinaryData());
        result.Content.Headers.ContentDisposition =
                new ContentDispositionHeaderValue("attachment") { FileName = $"{DateTime.Now.ToString("yyyyMMddmm")}.jpg" };
        result.Content.Headers.ContentType =
                new MediaTypeHeaderValue("image/jpeg");
        return result;
    }
<FunctionName("barcode")>
Public Shared Function Run(<HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route := Nothing)> ByVal req As HttpRequest, ByVal log As ILogger) As HttpResponseMessage
		log.LogInformation("C# HTTP trigger function processed a request.")
		IronXL.License.LicenseKey = "Key"
		Dim MyBarCode = BarcodeWriter.CreateBarcode("IronXL Test", BarcodeEncoding.QRCode)
		Dim result = New HttpResponseMessage(HttpStatusCode.OK)
		result.Content = New ByteArrayContent(MyBarCode.ToJpegBinaryData())
		result.Content.Headers.ContentDisposition = New ContentDispositionHeaderValue("attachment") With {.FileName = $"{DateTime.Now.ToString("yyyyMMddmm")}.jpg"}
		result.Content.Headers.ContentType = New MediaTypeHeaderValue("image/jpeg")
		Return result
End Function
VB   C#