IronXL 支援 .NET Core 的 AWS Lambda 功能

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 for 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 Function專案?

要在Visual Studio中建立AWS Lambda Function專案,請安裝Visual Studio的AWS工具套件。這將使您能夠使用AWS Lambda模板進行專案開發。您可以在AWS文件中找到詳細的指示。

IronXL在AWS Lambda中的範例應用程式是什麼?

IronXL在AWS Lambda中的一個範例應用程式是建立一個新的Excel工作簿,使用標籤資料填充它,並返回該Excel文件的Base64字串。這演示了IronXL如何在AWS Lambda functions中操作Excel文件。

我如何使用IronXL在AWS Lambda中將Excel工作簿轉換為Base64?

在AWS Lambda function中使用IronXL,您可以建立工作簿並使用workBook.ToByteArray()將其轉換為位元組陣列。然後使用Convert.ToBase64String()獲取該工作簿的Base64字串表示形式。

IronXL可以在AWS Lambda Functions中與.NET 5一起使用嗎?

是的,IronXL完全支援AWS Lambda Functions for .NET 5,還有.NET Standard Libraries、Core應用程式和.NET 6專案。

我可以在哪裡找到IronXL與AWS Lambda部署的資源?

IronXL與AWS Lambda部署的資源可以在IronXL NuGet安裝指南中找到,該指南提供使用IronXL NuGet套件進行部署的文件。

我如何在使用IronXL於AWS Lambda中排查問題?

確保您安裝了正確版本的IronXL和AWS工具套件。檢查程式碼是否有語法錯誤,並參考IronXL的文件以獲取與AWS Lambda的相容性詳情。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

準備好開始了嗎?
Nuget 下載 2,150,290 | 版本: 2026.7 剛剛發布
Still Scrolling Icon

仍在滾動嗎?

想要快速證明嗎? PM > Install-Package IronXL.Excel
運行一個範例 觀看您的資料成為試算表。