我可以在 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 函數支持

IronXL 支援 Azure Functions(Azure Functions V3)。 目前還沒有用 V4 進行過測試,但它已經在我們的計劃之中。

Azure 函數程式碼範例

已在 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 和條形碼,並從掃描圖像中讀取它們。已在包括 MVC 網站和 Azure 功能在內的各種 Azure 平台上進行了測試。

您所推薦的最佳性能所需的 Azure 託管級別是什麼?

為獲得最佳性能,我們建議使用 Azure B1 託管等級。如果您正在設計高吞吐量系統,可以考慮升級到更高層級。

哪個 .NET 框架在 Azure 上的效果最好?

IronXL 可在 Azure 上的 .NET Core 和 .NET Framework 上運行。然而,.NET Standard 應用程序在速度和穩定性方面提供了些許性能優勢,但需要更多內存。

Azure 的免費層是否足夠處理 QR?

Azure 的免費和共享層以及消耗計劃不建議用于使用 IronXL 處理 QR。我們建議使用 Azure B1 託管或 Premium 計劃以獲得更好的性能。

可以使用 Docker 管理 Azure 上的 IronXL 應用程序嗎?

是的,您可以使用 Docker 管理 Azure 上的 IronXL 應用程序和功能。此設置允許對性能進行更好的控制。Azure Docker 詳細教程可用于 Linux 和 Windows 實例。

IronXL 支持 Azure 功能嗎?

是的,IronXL 支持 Azure 功能 V3。對於 Azure 功能 V4 的測試正在進行中,計劃未來擴展支持。

我如何在 Azure 上安裝和使用 IronXL?

您可以通過命令 nuget install IronXL.Excel 來使用 NuGet 安裝 IronXL。

有使用 IronXL 與 Azure 功能的示例嗎?

是的,這篇文章提供了一個 Azure 功能代碼示例,該示例處理 HTTP 請求並返回 Excel 文件。此示例已在 Azure Functions v3.3.1.0+ 上進行測試。

Curtis Chau
技術撰稿人

Curtis Chau 擁有電腦科學學士學位(卡爾頓大學),專長於前端開發,精通 Node.js、TypeScript、JavaScript 和 React。Curtis 對製作直覺且美觀的使用者介面充滿熱情,他喜歡使用現代化的架構,並製作結構良好且視覺上吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 也有濃厚的興趣,他喜歡探索整合硬體與軟體的創新方式。在空閒時間,他喜歡玩遊戲和建立 Discord bots,將他對技術的熱愛與創意結合。

準備好開始了嗎?
Nuget 下載 1,846,091 | 版本: 2026.2 剛剛發布