IronXL 支援使用 .NET Core 的 AWS Lambda 函數
IronXL 完全支援 .NET 標準函式庫、核心應用程式、.NET 5 和 .NET 6 專案的 AWS Lambda 函數。
若要為 Visual Studio 新增 AWS Toolkit,請點擊此連結: 在 Visual Studio 的 AWS Toolkit 中使用 AWS Lambda 範本。
在 Visual Studio 中安裝 AWS Toolkit 後,即可建立 AWS Lambda 函數專案。 您可以透過此連結學習如何使用 Visual Studio 建立 AWS Lambda 函數專案。
AWS Lambda 函數程式碼範例
建立新的 AWS Lambda 函數專案後,您可以嘗試以下程式碼片段:
using System;
using Amazon.Lambda.Core;
using IronXL;
// Ensure this attribute targets your Lambda function
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace AWSLambdaIronXL
{
public class Function
{
/// <summary>
/// A simple function that takes a string input and processes it using IronXL.
/// This specific example creates a new Excel workbook and fills cells with labeled values.
/// </summary>
/// <param name="input">The string input for the function</param>
/// <param name="context">The Lambda context</param>
/// <returns>A Base64 string representation of the Excel file</returns>
public string FunctionHandler(string input, ILambdaContext context)
{
// Create a new workbook with ExcelFileFormat.XLS
WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLS);
// Create a new worksheet named "new_sheet"
var newSheet = workBook.CreateWorkSheet("new_sheet");
string columnNames = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
foreach (char col in columnNames)
{
for (int row = 1; row <= 50; row++)
{
// Construct cell name and fill it with data
var cellName = $"{col}{row}";
newSheet[cellName].Value = $"Cell: {cellName}";
}
}
// Convert the entire workbook to a byte array and then to a Base64 string
return Convert.ToBase64String(workBook.ToByteArray());
}
}
}using System;
using Amazon.Lambda.Core;
using IronXL;
// Ensure this attribute targets your Lambda function
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace AWSLambdaIronXL
{
public class Function
{
/// <summary>
/// A simple function that takes a string input and processes it using IronXL.
/// This specific example creates a new Excel workbook and fills cells with labeled values.
/// </summary>
/// <param name="input">The string input for the function</param>
/// <param name="context">The Lambda context</param>
/// <returns>A Base64 string representation of the Excel file</returns>
public string FunctionHandler(string input, ILambdaContext context)
{
// Create a new workbook with ExcelFileFormat.XLS
WorkBook workBook = WorkBook.Create(ExcelFileFormat.XLS);
// Create a new worksheet named "new_sheet"
var newSheet = workBook.CreateWorkSheet("new_sheet");
string columnNames = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
foreach (char col in columnNames)
{
for (int row = 1; row <= 50; row++)
{
// Construct cell name and fill it with data
var cellName = $"{col}{row}";
newSheet[cellName].Value = $"Cell: {cellName}";
}
}
// Convert the entire workbook to a byte array and then to a Base64 string
return Convert.ToBase64String(workBook.ToByteArray());
}
}
}可用於部署的 IronXL NuGet 套件已記錄在我們的IronXL NuGet 安裝指南中。
常見問題解答
如何在 Visual Studio 中建立 AWS Lambda 函數專案?
若要在 Visual Studio 中建立 AWS Lambda 函數項目,請安裝適用於 Visual Studio 的 AWS 工具包。安裝後,您就可以在專案中使用 AWS Lambda 範本。您可以在 AWS 文件中找到詳細說明。
IronXL 在 AWS Lambda 中的應用範例是什麼?
IronXL 在 AWS Lambda 中的一個應用範例是建立一個新的 Excel 工作簿,向其中填充帶有標籤的數據,並傳回該 Excel 檔案的 Base64 字串。這示範如何在 AWS Lambda 函數中使用 IronXL 來操作 Excel 檔案。
如何使用 IronXL 在 AWS Lambda 中將 Excel 工作簿轉換為 Base64 編碼?
在 AWS Lambda 函數中使用 IronXL,您可以建立一個工作簿,並使用workBook.ToByteArray()將其轉換為位元組陣列。然後,使用Convert.ToBase64String()取得工作簿的 Base64 字串表示形式。
IronXL 能否與 AWS Lambda Functions 中的 .NET 5 一起使用?
是的,IronXL 完全支援 .NET 5 的 AWS Lambda 函數,以及 .NET 標準函式庫、核心應用程式和 .NET 6 專案。
在哪裡可以找到有關使用 AWS Lambda 部署 IronXL 的資源?
有關使用 AWS Lambda 部署 IronXL 的資源,請參閱 IronXL NuGet 安裝指南,其中提供了有關使用 IronXL NuGet 套件進行部署的文件。
使用IronXL於AWS Lambda時,如何追蹤問題?
請確保您已安裝正確版本的 IronXL 和 AWS Toolkit。檢查程式碼是否有語法錯誤,並參考 IronXL 的文件以了解與 AWS Lambda 的兼容性詳情。






