IronXL 開始使用 AWS Lambda 支援 IronXL Support for AWS Lambda Function with .NET Core Curtis Chau 更新日期:6月 1, 2025 Download IronXL NuGet 下載 DLL 下載 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article This article was translated from English: Does it need improvement? Translated View the article in English IronXL 完全支持用於 .NET Standard 函式庫、Core 應用程式、.NET 5 和 .NET 6 專案的 AWS Lambda 函式。 要新增 AWS ToolKit 至 Visual Studio,請參考此連結:使用 AWS Toolkit for Visual Studio 的 AWS Lambda 模板。 將 AWS Toolkit 安裝於 Visual Studio 可讓您建立 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()); } } } Imports System Imports Amazon.Lambda.Core Imports IronXL ' Ensure this attribute targets your Lambda function <Assembly: LambdaSerializer(GetType(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 Function FunctionHandler(ByVal input As String, ByVal context As ILambdaContext) As String ' Create a new workbook with ExcelFileFormat.XLS Dim workBook As WorkBook = WorkBook.Create(ExcelFileFormat.XLS) ' Create a new worksheet named "new_sheet" Dim newSheet = workBook.CreateWorkSheet("new_sheet") Dim columnNames As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" For Each col As Char In columnNames For row As Integer = 1 To 50 ' Construct cell name and fill it with data Dim cellName = $"{col}{row}" newSheet(cellName).Value = $"Cell: {cellName}" Next row Next col ' Convert the entire workbook to a byte array and then to a Base64 string Return Convert.ToBase64String(workBook.ToByteArray()) End Function End Class End Namespace $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 立即與工程團隊聊天 技術作家 Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。 準備好開始了嗎? Nuget 下載 1,686,155 | 版本: 2025.11 剛剛發布 免費 NuGet 下載 總下載量:1,686,155 查看許可證