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.

Preguntas Frecuentes

¿Cómo puedo crear un Proyecto de Función Lambda de AWS en Visual Studio?

Para crear un Proyecto de Función Lambda de AWS en Visual Studio, instale AWS Toolkit para Visual Studio. Esto le permite usar las Plantillas Lambda de AWS para sus proyectos. Puede encontrar instrucciones detalladas en la documentación de AWS.

¿Cuál es una aplicación de ejemplo de IronXL en AWS Lambda?

Un ejemplo de aplicación de IronXL en AWS Lambda es crear un nuevo libro de trabajo de Excel, llenarlo con datos etiquetados y devolver una cadena Base64 del archivo de Excel. Esto demuestra cómo se puede usar IronXL para manipular archivos Excel dentro de funciones Lambda de AWS.

¿Cómo convierto un libro de trabajo de Excel a Base64 en AWS Lambda usando IronXL?

Usando IronXL dentro de una función Lambda de AWS, puede crear un libro de trabajo y convertirlo a un arreglo de bytes con workBook.ToByteArray(). Luego, use Convert.ToBase64String() para obtener una representación en cadena Base64 del libro de trabajo.

¿Se puede usar IronXL con .NET 5 en Funciones Lambda de AWS?

Sí, IronXL es totalmente compatible con las Funciones Lambda de AWS para .NET 5, así como con Bibliotecas .NET Standard, aplicaciones Core y proyectos .NET 6.

¿Dónde puedo encontrar recursos para desplegar IronXL con AWS Lambda?

Los recursos para desplegar IronXL con AWS Lambda se pueden encontrar en la guía de instalación de NuGet de IronXL, que proporciona documentación sobre el uso de los Paquetes NuGet de IronXL para sus despliegues.

¿Cómo puedo solucionar problemas al usar IronXL en AWS Lambda?

Asegúrese de tener instalada la versión correcta de IronXL y AWS Toolkit. Revise el código para detectar cualquier error de sintaxis y consulte la documentación de IronXL para obtener detalles de compatibilidad con AWS Lambda.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 1,686,155 | Versión: 2025.11 recién lanzado