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 unterstützt vollständig AWS Lambda-Funktion für .NET Standard-Bibliotheken, Core-Anwendungen, .NET 5 und .NET 6 Projekte.

Um das AWS ToolKit für Visual Studio hinzuzufügen, folgen Sie diesem Link: Verwenden der AWS Lambda-Vorlagen im AWS Toolkit für Visual Studio.

Die Installation des AWS Toolkit in Visual Studio ermöglicht es Ihnen, ein AWS Lambda-Funktionsprojekt zu erstellen. Sie können lernen, wie Sie ein AWS Lambda-Funktionsprojekt mit Visual Studio erstellen, über diesen Link.

Funktionsfähiges AWS Lambda-Funktions-Beispiel

Nach dem Erstellen eines neuen AWS Lambda-Funktionsprojekts können Sie diesen Code-Schnipsel ausprobieren:

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-Pakete, die für Bereitstellungen verfügbar sind, werden in unserem IronXL NuGet-Installationshandbuch dokumentiert.

Häufig gestellte Fragen

Wie kann ich ein AWS Lambda-Funktionsprojekt in Visual Studio erstellen?

Um ein AWS Lambda-Funktionsprojekt in Visual Studio zu erstellen, installieren Sie das AWS Toolkit für Visual Studio. Dies ermöglicht Ihnen die Nutzung von AWS Lambda-Vorlagen für Ihre Projekte. Ausführliche Anleitungen finden Sie in der AWS-Dokumentation.

Was ist ein Anwendungsbeispiel von IronXL in AWS Lambda?

Ein Anwendungsbeispiel von IronXL in AWS Lambda ist das Erstellen einer neuen Excel-Arbeitsmappe, das Füllen mit beschrifteten Daten und das Zurückgeben eines Base64-Strings der Excel-Datei. Dies demonstriert, wie IronXL zur Bearbeitung von Excel-Dateien innerhalb von AWS Lambda-Funktionen eingesetzt werden kann.

Wie konvertiere ich eine Excel-Arbeitsmappe in Base64 in AWS Lambda mit IronXL?

Durch die Verwendung von IronXL innerhalb einer AWS Lambda-Funktion können Sie eine Arbeitsmappe erstellen und in ein Byte-Array mit workBook.ToByteArray() konvertieren. Verwenden Sie dann Convert.ToBase64String(), um eine Base64-String-Repräsentation der Arbeitsmappe zu erhalten.

Kann IronXL mit .NET 5 in AWS Lambda-Funktionen verwendet werden?

Ja, IronXL unterstützt vollumfänglich AWS Lambda-Funktionen für .NET 5 sowie für .NET-Standardbibliotheken, Core-Anwendungen und .NET 6 Projekte.

Wo finde ich Ressourcen für die Bereitstellung von IronXL mit AWS Lambda?

Ressourcen für die Bereitstellung von IronXL mit AWS Lambda finden Sie im IronXL NuGet-Installationsleitfaden, der Dokumentationen zur Verwendung der IronXL NuGet-Pakete für Ihre Implementierungen bietet.

Wie kann ich Probleme bei der Verwendung von IronXL in AWS Lambda beheben?

Stellen Sie sicher, dass Sie die richtige Version von IronXL und AWS Toolkit installiert haben. Überprüfen Sie den Code auf Syntaxfehler und verweisen Sie auf die IronXL-Dokumentation für Kompatibilitätsdetails mit AWS Lambda.

Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen
Bereit anzufangen?
Nuget Downloads 1,686,155 | Version: 2025.11 gerade veröffentlicht