IronXL-Unterstützung für AWS Lambda Function mit .NET Core
IronXL unterstützt vollständig die AWS Lambda-Funktion für .NET Standard 2.0-Bibliotheken, Core-Anwendungen, .NET 8 und .NET 10-Projekte.
Um das AWS Toolkit für Visual Studio hinzuzufügen, folgen Sie diesem Link: Verwendung 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 man ein AWS Lambda Function-Projekt mit Visual Studio erstellt, ü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());
}
}
}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(input As String, 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
Next
' Convert the entire workbook to a byte array and then to a Base64 string
Return Convert.ToBase64String(workBook.ToByteArray())
End Function
End Class
End NamespaceImports 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(input As String, 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
Next
' Convert the entire workbook to a byte array and then to a Base64 string
Return Convert.ToBase64String(workBook.ToByteArray())
End Function
End Class
End NamespaceIronXL NuGet-Pakete für Bereitstellungen sind in unserem IronXL NuGet-Installationsleitfaden dokumentiert.
Häufig gestellte Fragen
Welche Versionen von .NET unterstützt IronXL für AWS Lambda-Funktionen?
IronXL unterstützt AWS Lambda-Funktion für .NET Standard 2.0 Bibliotheken, Core-Anwendungen, .NET 8 und .NET 10 Projekte.
Wie kann ich ein AWS Lambda-Projekt mit IronXL starten?
Um ein AWS Lambda-Projekt mit IronXL zu starten, installieren Sie zunächst das AWS-Toolkit in Visual Studio, um die Projekterstellung zu ermöglichen. Folgen Sie dann den AWS Lambda-Templates im AWS-Toolkit für Visual Studio für Anleitungen.
Gibt es ein Code-Beispiel für die Verwendung von IronXL mit AWS Lambda?
Ja, das bereitgestellte Code-Beispiel zeigt, wie man ein neues Excel-Arbeitsbuch erstellt, Zellen mit Daten füllt und einen Base64-String mithilfe von IronXL in einer AWS Lambda-Funktion zurückgibt.
Kann IronXL Excel-Dateien innerhalb einer AWS Lambda-Funktion erstellen?
Ja, IronXL kann Excel-Dateien innerhalb einer AWS Lambda-Funktion erstellen, indem es seine Funktionen nutzt, um Excel-Arbeitsbücher und -Arbeitsblätter programmatisch zu konstruieren.
Wie konvertiere ich ein Excel-Arbeitsbuch mit IronXL in einen Base64-String?
Sie können ein Excel-Arbeitsbuch in IronXL in einen Base64-String konvertieren, indem Sie zuerst das Arbeitsbuch in ein Byte-Array konvertieren und dann die Convert.ToBase64String-Methode verwenden.
Was ist der Zweck der 'FunctionHandler'-Methode im IronXL AWS Lambda-Beispiel?
Die 'FunctionHandler'-Methode im IronXL AWS Lambda-Beispiel verarbeitet eine Zeichenkette Eingabe, generiert ein Excel-Arbeitsbuch, indem sie Zellen mit beschrifteten Werten füllt, und gibt das Arbeitsbuch als Base64-String zurück.
Welche AWS-Ressource kann ich für detaillierte Anweisungen zur Bereitstellung eines IronXL-Projekts in AWS Lambda verwenden?
Detaillierte Anweisungen zur Bereitstellung eines IronXL-Projekts als AWS Lambda-Funktion finden Sie in der AWS-Dokumentation unter AWS Lambda-Templates im AWS-Toolkit für Visual Studio.
Wo finde ich die IronXL NuGet-Installationsanleitung?
Die IronXL NuGet-Installationsanleitung ist im Dokumentationsbereich auf der Webseite von Iron Software verfügbar, speziell in der IronXL NuGet-Installationsanleitung.
Wie erstelle ich ein neues Arbeitsblatt in einem Excel-Arbeitsbuch mit IronXL?
In IronXL können Sie ein neues Arbeitsblatt in einer Excel-Arbeitsmappe mithilfe der CreateWorkSheet-Methode erstellen. Zum Beispiel erstellt var newSheet = workBook.CreateWorkSheet("new_sheet"); ein Blatt mit dem Namen 'new_sheet'.
Welchen Vorteil bietet die Verwendung von IronXL mit AWS Lambda?
Die Verwendung von IronXL mit AWS Lambda ermöglicht eine nahtlose Integration von .NET-Anwendungen mit AWS-Cloud-Services, wodurch die programmatische Erstellung und Manipulation von Excel-Dateien in serverlosen Umgebungen ermöglicht wird.
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 Handbücher.