In this article, you will discover how to copy sheets from several Excel workbooks into one workbook using C#, and also how to merge data from multiple worksheets into a single sheet. Let’s start.

C# API to Merge Multiple Excel files

Aspose.Cells for .NET is a well‑known spreadsheet manipulation API that lets you create and process Excel files from within your .NET applications. You can either download the binaries of the API or get it installed using NuGet.

PM> Install-Package Aspose.Cells

Combine Multiple Excel Files into One using C#

Sometimes you need to merge several Excel files into a single workbook. You want to copy worksheets from the source workbooks to the destination workbook as shown below. Excel documents can be any version such as Excel 97, 2010, or 2016.

Combine Multiple Excel Files into One using C#

Fig 1: Combine Excel Files

The following sample code shows how to combine multiple Excel files into one using C#.

Combine Specific Worksheets of Excel Files using C#

The code above copies all worksheets from the source files to the destination file. Often you only need specific worksheets. For example, you have two Excel files, each with worksheets named Sales, Employees, and Expenses. You only want to copy the Sales worksheet from both files to the destination file, as shown in the figure.

Combine Specific Worksheets of Excel Files using C#

Fig 2: Combine Specific Worksheets of Excel Files

The sample code below demonstrates how to combine specific worksheets from source files into a destination file using C#.

Merge Multiple Worksheets into One using C#

Sometimes you need to copy data from several worksheets into a single worksheet. For example, you have multiple sheets in an Excel file that contain product information, and you want to merge them into one summary sheet, like this:

Merge Multiple Worksheets into One using C#

Fig 3: Merge Multiple Worksheets into One

The code snippet below shows how to copy data from several worksheets into one worksheet using C#.

Conclusion

In this article, you learned how to programmatically combine multiple Excel files into one workbook. You can copy all worksheets or select specific ones, and you can also merge data from several worksheets into a single sheet. See the documentation of Aspose.Cells for .NET for more details. If you have questions, ask in our Support Forum; we’ll respond within a few hours.

See Also