IronXL Support for AWS Lambda Function with .NET Core
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
IronXL NuGet Packages available for deployments are documented in our IronXL NuGet installation guide.
Frequently Asked Questions
How can I create an AWS Lambda Function Project in Visual Studio?
To create an AWS Lambda Function Project in Visual Studio, install the AWS Toolkit for Visual Studio. This enables you to use AWS Lambda Templates for your projects. You can find detailed instructions in the AWS documentation.
What is an example application of IronXL in AWS Lambda?
An example application of IronXL in AWS Lambda is creating a new Excel workbook, filling it with labeled data, and returning a Base64 string of the Excel file. This demonstrates how IronXL can be used to manipulate Excel files within AWS Lambda functions.
How do I convert an Excel workbook to Base64 in AWS Lambda using IronXL?
Using IronXL within an AWS Lambda function, you can create a workbook and convert it to a byte array with workBook.ToByteArray()
. Then, use Convert.ToBase64String()
to obtain a Base64 string representation of the workbook.
Can IronXL be used with .NET 5 in AWS Lambda Functions?
Yes, IronXL fully supports AWS Lambda Functions for .NET 5, as well as .NET Standard Libraries, Core applications, and .NET 6 projects.
Where can I find resources for deploying IronXL with AWS Lambda?
Resources for deploying IronXL with AWS Lambda can be found in the IronXL NuGet installation guide, which provides documentation on using the IronXL NuGet Packages for your deployments.
How can I troubleshoot issues when using IronXL in AWS Lambda?
Ensure that you have the correct version of IronXL and AWS Toolkit installed. Review the code for any syntax errors and refer to IronXL's documentation for compatibility details with AWS Lambda.