IronXL による .NET Core を使用した AWS Lambda 関数のサポート
IronXLはAWS Lambda関数を.NET Standardライブラリ、Coreアプリケーション、.NET 5、.NET 6プロジェクト向けに完全サポートしています。
Visual Studio用AWS ToolKitを追加するには、こちらのリンクを参照してください: Visual StudioのAWS ToolkitでAWS Lambdaテンプレートを使用する。
AWS ToolkitをVisual Studioにインストールすることで、AWS Lambda関数プロジェクトを作成できます。 Visual Studioを使用してAWS Lambda関数プロジェクトを作成する方法について、このリンクから学べます。
動作するAWS Lambda関数コード例
新しいAWS Lambda関数プロジェクトを作成した後、このコードスニペットを試すことができます:
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パッケージは、IronXL NuGetインストールガイドに記載されています。
よくある質問
Visual Studio で AWS Lambda Function Project をどのように作成できますか?
Visual Studio で AWS Lambda Function Project を作成するには、AWS Toolkit for Visual Studio をインストールします。これにより、プロジェクト用のAWS Lambda テンプレートを使用できます。詳しい手順は AWS ドキュメントで確認できます。
AWS Lambda における IronXL のアプリケーションの例は何ですか?
IronXL を AWS Lambda で使用する例として、新しい Excel ワークブックを作成し、ラベル付きデータで埋め、それを Excel ファイルの Base64 文字列として返す方法が示されています。これにより、AWS Lambda 関数内で Excel ファイルを操作するために IronXL がどのように使用できるかが示されています。
IronXL を使用して AWS Lambda で Excel ワークブックを Base64 に変換する方法は?
AWS Lambda 関数内で IronXL を使用すると、ワークブックを作成し、それを workBook.ToByteArray() でバイト配列に変換できます。次に、Convert.ToBase64String() を使用して、ワークブックの Base64 文字列表現を取得します。
AWS Lambda Functions で .NET 5 と一緒に IronXL を使用できますか?
はい、IronXL は .NET 5 向けの AWS Lambda Functions を完全にサポートしており、.NET Standard Libraries、Core アプリケーション、および .NET 6 プロジェクトをサポートします。
AWS Lambda と IronXL をデプロイするためのリソースはどこで見つけられますか?
IronXL NuGet インストール ガイドには、AWS Lambda と IronXL をデプロイするためのドキュメントがあり、IronXL NuGet パッケージを利用したデプロイメントに関する情報を提供しています。
AWS Lambda で IronXL を使用する際の問題をどのようにトラブルシューティングできますか?
IronXL と AWS Toolkit の正しいバージョンがインストールされていることを確認してください。構文エラーがないかコードを見直し、AWS Lambda との互換性の詳細についてはIronXL のドキュメントを参照してください。






