IronXL Support for AWS Lambda Function with .NET Core

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

IronXL fully supports AWS Lambda Function for .NET Standard Libraries, Core applications, .NET 5, and .NET 6 projects.

To add AWS ToolKit for Visual Studio, follow this link: Using the AWS Lambda Templates in the AWS Toolkit for Visual Studio.

Installing AWS Toolkit into Visual Studio enables you to create an AWS Lambda Function Project. You can learn how to create an AWS Lambda Function Project using Visual Studio through this link.

Working AWS Lambda Function Code Example

After creating a new AWS Lambda Function project, you can try this code snippet:

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 Packages available for deployments are documented in our IronXL NuGet installation guide.

Questions Fréquemment Posées

Comment puis-je créer un projet de fonction AWS Lambda dans Visual Studio?

Pour créer un projet de fonction AWS Lambda dans Visual Studio, installez AWS Toolkit pour Visual Studio. Cela vous permet d'utiliser les modèles AWS Lambda pour vos projets. Vous pouvez trouver des instructions détaillées dans la documentation AWS.

Quel est un exemple d'application d'IronXL dans AWS Lambda?

Un exemple d'application d'IronXL dans AWS Lambda est la création d'un nouveau classeur Excel, son remplissage avec des données étiquetées et le retour d'une chaîne Base64 du fichier Excel. Cela démontre comment IronXL peut être utilisé pour manipuler des fichiers Excel au sein des fonctions AWS Lambda.

Comment puis-je convertir un classeur Excel en Base64 dans AWS Lambda à l'aide d'IronXL?

En utilisant IronXL au sein d'une fonction AWS Lambda, vous pouvez créer un classeur et le convertir en un tableau d'octets avec workBook.ToByteArray(). Ensuite, utilisez Convert.ToBase64String() pour obtenir une représentation de chaîne Base64 du classeur.

IronXL peut-il être utilisé avec .NET 5 dans les fonctions AWS Lambda?

Oui, IronXL prend entièrement en charge les fonctions AWS Lambda pour .NET 5, ainsi que les bibliothèques .NET Standard, les applications Core et les projets .NET 6.

Où puis-je trouver des ressources pour déployer IronXL avec AWS Lambda?

Des ressources pour déployer IronXL avec AWS Lambda se trouvent dans le guide d'installation IronXL NuGet, qui fournit une documentation sur l'utilisation des IronXL NuGet Packages pour vos déploiements.

Comment puis-je dépanner les problèmes lors de l'utilisation d'IronXL dans AWS Lambda?

Assurez-vous d'avoir la version correcte d'IronXL et AWS Toolkit installée. Vérifiez le code pour toute erreur de syntaxe et consultez la documentation d'IronXL pour des détails de compatibilité avec AWS Lambda.

Curtis Chau
Rédacteur technique

Curtis Chau détient un baccalauréat en informatique (Université de Carleton) et se spécialise dans le développement front-end avec expertise en Node.js, TypeScript, JavaScript et React. Passionné par la création d'interfaces utilisateur intuitives et esthétiquement plaisantes, Curtis aime travailler avec des frameworks modernes ...

Lire la suite
Prêt à commencer?
Nuget Téléchargements 1,686,155 | Version : 2025.11 vient de sortir