我可以在 Azure 上使用 .NET 執行 IronXL 嗎?
是的,IronXL 可在 Azure 上使用,用於在 C# 和 VB .NET 應用程式中生成 QR 碼與 BarCode,並能從掃描的影像中讀取 BarCode 與 QR 碼。
IronXL 已在多個 Azure 平台上經過徹底測試,包括 MVC 網站、Azure Functions 以及更多其他平台。
步驟 1
1. 安裝 IronXL 開始使用
首先透過 NuGet 安裝:
Install-Package IronXL.Excel
操作教學
2. 效能與 Azure 服務層級
我們建議 Azure B1 託管層級非常適合終端使用者的函式庫需求。 若開發者正在建置高吞吐量系統,可能需要進行升級。
3. 框架選擇
我們發現 IronXL for Core 和 IronXL for Framework 皆可在 Azure 上運作。 .NET Standard 應用程式在速度與穩定性方面似乎略具優勢,但在執行過程中會消耗更多記憶體。
Azure 免費層級的託管速度較慢
Azure 的免費與共享層級,以及用量方案,均不適用於 QR 碼處理。 我們建議選用 Azure B1 託管/Premium 方案,這也是我們自己使用的方案。
4. Azure 上的 Docker
在 Azure 上掌控效能的一種方法,是透過 Docker 容器內使用 IronXL 應用程式和 Functions。
我們提供一份針對 Linux 和 Windows 執行個體的完整 IronXL Azure Docker 教學指南,建議您詳閱。
5. 正式支援 Azure Function
IronXL 支援 Azure Function(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.Co/ntent = new ByteArrayContent(workBook.ToByteArray());
result.Co/ntent.Headers.Co/ntentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = $"{DateTime.Now:yyyyMMddmm}.xlsx"
};
result.Co/ntent.Headers.Co/ntentType = 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.Co/ntent = new ByteArrayContent(workBook.ToByteArray());
result.Co/ntent.Headers.Co/ntentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = $"{DateTime.Now:yyyyMMddmm}.xlsx"
};
result.Co/ntent.Headers.Co/ntentType = 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)> req As HttpRequest,
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
常見問題
如何在 Azure 上執行 .NET 應用程式?
您可以使用 IronXL 在 Azure 上執行 .NET 應用程式。它允許在 C# 和 VB .NET 應用程式中產生 QR 碼與 BARCODE,並從掃描的影像中讀取這些碼。該工具已在各種 Azure 平台上經過測試,包括 MVC 網站和 Azure Functions。
要獲得最佳效能,建議採用哪些 Azure 託管層級?
為確保 IronXL 發揮最佳效能,我們建議選用 Azure B1 託管層級。若您正在設計高吞吐量系統,請考慮升級至更高階層級。
哪個 .NET Framework 在 Azure 上運作最順暢?
IronXL 可在 Azure 上的 .NET Core 和 .NET Framework 環境中運作。然而,儘管 .NET Standard 應用程式會增加記憶體使用量,但在速度與穩定性方面仍略勝一籌。
Azure 的免費方案是否足以處理 QR 碼?
不建議在 IronXL 的 QR 碼處理中使用 Azure 的免費和共享層級,以及用量方案。相反地,我們建議使用 Azure B1 託管或 Premium 方案以獲得更好的效能。
能否使用 Docker 在 Azure 上管理 IronXL 應用程式?
是的,您可以使用 Docker 來管理 Azure 上的 IronXL 應用程式和 Functions。此設定可讓您更有效地控制效能。我們提供適用於 Linux 和 Windows 執行個體的詳細 Azure Docker 教學指南。
IronXL 是否支援 Azure Functions?
是的,IronXL 支援 Azure Functions V3。目前正在針對 Azure Functions V4 進行測試,並計劃於未來擴展支援範圍。
如何安裝 IronXL 以便在 Azure 上使用?
您可以透過以下指令,使用 NuGet 安裝 IronXL: nuget install IronXL.Excel.
是否有 IronXL 搭配 Azure Functions 使用的範例?
是的,本文提供了一個 Azure Function 範例程式碼,用於處理 HTTP 請求並回傳 Excel 檔案。此範例已在 Azure Functions v3.3.1.0 以上版本進行測試。

