Skip to content

Instantly share code, notes, and snippets.

@aspose-com-kb
Last active February 8, 2026 10:01
Show Gist options
  • Select an option

  • Save aspose-com-kb/e21bbdce70045c41c8064b1409f1bd74 to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-kb/e21bbdce70045c41c8064b1409f1bd74 to your computer and use it in GitHub Desktop.
Merge Excel Files using C#. For more details: https://kb.aspose.com/cells/net/merge-excel-files-using-csharp/
using Aspose.Cells;
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
// License
var lic = new License();
lic.SetLicense("license.lic");
// 1. Create a list of Excel files
List<string> excelFiles = new List<string>
{
@"File1.xlsx",
@"File2.xlsx",
@"File3.xlsx",
@"File4.xlsx",
@"File5.xlsx",
@"File6.xlsx",
};
if (excelFiles.Count == 0)
{
Console.WriteLine("No files to combine.");
return;
}
// 2. Load the first workbook as the destination
Workbook combinedWorkbook = new Workbook(excelFiles[0]);
// 3. Combine remaining workbooks
for (int i = 1; i < excelFiles.Count; i++)
{
Workbook tempWorkbook = new Workbook(excelFiles[i]);
combinedWorkbook.Combine(tempWorkbook);
}
// 4. Save the combined workbook
combinedWorkbook.Save(@"CombinedOutput.xlsx");
Console.WriteLine("Excel files combined successfully.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment