我可以在 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 與 BarCode,並從掃描的影像中讀取它們。它已在各種 Azure 平台上進行測試,包括 MVC 網站和 Azure 函式。

要達到最佳效能,建議的 Azure 主機層級為何?

為了讓 IronXL 達到最佳效能,我們建議使用 Azure B1 主機等級。如果您正在設計高吞吐量系統,請考慮升級到更高的層級。

哪種 .NET Framework 在 Azure 上運作得最好?

IronXL 可在 Azure 上的 .NET Core 和 .NET Framework 上運作。但是,.NET Standard 應用程式在速度和穩定性方面略有效能優勢,儘管會增加記憶體使用量。

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

Azure 的免費和共用層級,以及消費計畫,不建議使用 IronXL 進行 QR 處理。相反,我們建議使用 Azure B1 主機或 Premium 計劃,以獲得更好的效能。

Docker 可以用來管理 Azure 上的 IronXL 應用程式嗎?

是的,您可以使用 Docker 來管理 Azure 上的 IronXL 應用程式和 Functions。這種設定可以更好地控制效能。詳細的 Azure Docker 教學適用於 Linux 和 Windows 實體。

IronXL 支援 Azure Functions 嗎?

是的,IronXL 支援 Azure Functions V3。Azure Functions V4 的測試正在進行中,並計劃在未來擴大支援範圍。

如何安裝 IronXL 以在 Azure 上使用?

您可以使用命令透過 NuGet 安裝 IronXL:nuGet install IronXL.Excel

是否有將 IronXL 與 Azure Functions 搭配使用的範例?

是的,文章提供了處理 HTTP 請求並傳回 Excel 檔案的 Azure Function 程式碼範例。此範例在 Azure Functions v3.3.1.0+ 上進行測試。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

準備好開始了嗎?
Nuget 下載 1,738,553 | Version: 2025.11 剛發表