IronXL로 AWS Lambda에서 Excel 파일 처리하기
IronXL은 .NET Standard 라이브러리, Core 애플리케이션, .NET 5 및 .NET 6 프로젝트에 대한 AWS Lambda 함수를 완벽하게 지원합니다. IronXL을 활용하면 AWS 클라우드 환경에서 xlsx 파일을 생성하고 편집할 수 있습니다.
Visual Studio용 AWS 툴킷 추가 방법은 다음 링크를 참조하세요: AWS Toolkit for Visual Studio의 AWS Lambda 템플릿 사용.
Visual Studio에 AWS Toolkit을 설치하면 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 함수 프로젝트를 어떻게 생성할 수 있나요?
Visual Studio에서 AWS Lambda 함수 프로젝트를 생성하려면 Visual Studio용 AWS 툴킷을 설치해야 합니다. 이를 통해 프로젝트에서 AWS Lambda 템플릿을 사용할 수 있습니다. 자세한 지침은 AWS 설명서를 참조하십시오.
AWS Lambda에서 IronXL을 사용하는 예시 애플리케이션은 무엇인가요?
AWS Lambda에서 IronXL을 사용하는 예시로는 새 Excel 통합 문서를 생성하고, 레이블이 지정된 데이터를 채운 다음, Excel 파일의 내용을 Base64 문자열로 반환하는 것이 있습니다. 이는 IronXL을 사용하여 AWS Lambda 함수 내에서 Excel 파일을 조작하는 방법을 보여줍니다.
AWS Lambda에서 IronXL을 사용하여 Excel 통합 문서를 Base64로 변환하는 방법은 무엇인가요?
AWS Lambda 함수 내에서 IronXL을 사용하면 워크북을 생성하고 workBook.ToByteArray() 를 사용하여 바이트 배열로 변환할 수 있습니다. 그런 다음 Convert.ToBase64String() 사용하여 워크북의 Base64 문자열 표현을 얻을 수 있습니다.
IronXL을 AWS Lambda 함수에서 .NET 5와 함께 사용할 수 있습니까?
네, IronXL은 .NET 5용 AWS Lambda 함수는 물론 .NET Standard 라이브러리, Core 애플리케이션 및 .NET 6 프로젝트를 완벽하게 지원합니다.
AWS Lambda를 사용하여 IronXL을 배포하는 데 필요한 자료는 어디에서 찾을 수 있나요?
AWS Lambda를 사용하여 IronXL을 배포하는 데 필요한 리소스는 IronXL NuGet 설치 가이드에서 찾을 수 있으며, 이 가이드에는 IronXL NuGet 패키지를 사용하여 배포하는 방법에 대한 문서가 포함되어 있습니다.
AWS Lambda에서 IronXL을 사용할 때 발생하는 문제를 어떻게 해결할 수 있나요?
IronXL과 AWS Toolkit의 올바른 버전이 설치되어 있는지 확인하십시오. 코드에 구문 오류가 있는지 검토하고 AWS Lambda와의 호환성에 대한 자세한 내용은 IronXL 설명서를 참조하십시오.

