Microsoft® Excel 파일 병합 via .NET

C# 코드를 사용하여 단일 스프레드시트에 2개 이상의 Excel 파일을 결합합니다.

 

.NET 엑셀 라이브러리 수식, 데이터, 이미지, 차트 등과 같은 다양한 유형의 콘텐츠가 포함된 통합 문서를 단일 스프레드시트 파일로 결합하는 다양한 방법을 제공합니다. 지원되는 파일 형식에는 XLS, XLSX, XLSB, XLT, XLTX, XLTM, ODS, CSV, TSV 등이 있습니다.

Excel 파일을 이미지 및 차트와 결합

이미지와 차트가 있는 2개의 Excel 파일을 결합하는 가장 간단한 방법은 통합 문서.결합 방법. 유사한 유형의 Excel 파일을 단일 스프레드시트로 병합할 수 있습니다.

C# Excel 파일을 결합하는 코드
// load first Excel file
var book1 = new Aspose.Cells.Workbook("withCharts.xlsx");
// load second Excel file into a separate instance
var book2 = new Aspose.Cells.Workbook("withImages.xlsx");
// combine two workbooks
book1.Combine(book2);
// save the target workbook
book1.Save("combined.xlsx");

여러 Excel 파일 병합

CellsHelper.MergeFiles 이 방법은 Excel 파일의 데이터, 스타일 및 수식을 동일한 형식의 새 스프레드시트에 병합하는 것을 지원합니다. 캐싱을 사용하면서 여러 파일을 병합하는 효율적인 방법입니다.

C# 여러 Excel 파일을 병합하는 코드
// create an Array (length=2)
String[] files = new String[2];
// specify file paths to be merged
files[0] = "Book1.xls";
files[1] = "Book2.xls";
// merge the files to save the result
Aspose.Cells.CellsHelper.MergeFiles(files, "cache", "merged.xls");

워크시트를 복사하여 Excel 파일 병합

워크시트.복사 통합 문서 내 또는 통합 문서 간에 원본 워크시트의 데이터 및 서식을 다른 워크시트로 복사하는 데 사용할 수 있습니다. 이 메서드는 원본 워크시트 개체를 매개 변수로 사용합니다.

C# Excel 파일 간에 워크시트를 복사하는 코드
// load spreadsheet files into 2 instances of Workbook
var book1 = new Aspose.Cells.Workbook("input.xlsx");
var book2 = new Aspose.Cells.Workbook("input.ods");
// loop over the worksheet collection
foreach (var sheet in book1.Worksheets)
{
// add a blank worksheet
book2.Worksheets.Add(sheet.Name);
// copy worksheet from source to target
book2.Worksheets[sheet.Name].Copy(sheet);
}
// Save the file in any spreadsheet format
book2.Save("combined.xls", Aspose.Cells.SaveFormat.Auto);

기타 지원되는 병합 형식

C#을 사용하면 다음을 포함한 다른 많은 파일 형식을 병합할 수도 있습니다.

CSV (쉼표로 구분된 값)
HTML (하이퍼텍스트 마크업 언어)
MHTML (웹페이지 아카이브 형식)
ODS (OpenDocument 스프레드시트 파일)
TSV (탭으로 구분된 값)
TXT (텍스트 문서)
XLS (Excel 바이너리 형식)
XLSB (바이너리 Excel 통합 문서 파일)
XLSM (스프레드시트 파일)
XLSX (OOXML 엑셀 파일)
XLT (Microsoft 엑셀 템플릿)
XLTM (Excel 매크로 지원 템플릿)