IronXL 支援使用 .NET Core 的 AWS Lambda 函數

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

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());
        }
    }
}
$vbLabelText   $csharpLabel

可用於部署的 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 的兼容性詳情。

柯蒂斯·週
技術撰稿人

Curtis Chau擁有卡爾頓大學電腦科學學士學位,專長於前端開發,精通Node.js、TypeScript、JavaScript和React。他熱衷於打造直覺美觀的使用者介面,喜歡使用現代框架,並擅長撰寫結構清晰、視覺效果出色的使用者手冊。

除了開發工作之外,柯蒂斯對物聯網 (IoT) 也抱有濃厚的興趣,致力於探索硬體和軟體整合的創新方法。閒暇時,他喜歡玩遊戲和製作 Discord 機器人,將他對科技的熱愛與創造力結合。

準備好開始了嗎?
Nuget 下載 1,802,965 | 版本: 2025.12 剛剛發布