This short guide explains how to merge Excel files using C#. It has details to set the IDE, a list of instructions, and a sample code to combine multiple Excel files using C#. You will get a ready-to-run application to perform this task instantly.
Steps to Combine Excel Files using C#
- Set the environment using Aspose.Cells for .NET to combine multiple Excel files
- Insert the required using directives for enabling the desired classes and enumerators
- Build a list of Excel files by setting the paths of all the source Excel files
- Load the first Excel file into the Workbook class that will become the final combined Excel file
- Loop through all the Excel files in the list, load each into the Workbook object using the Combine Method
- Save the above-mentioned first Excel file as a combined output Excel file
The above steps have summarized how to join Excel files using C#. Import the necessary classes and enumerators with the using directive, load the license, create a list of Excel files and exit the program if the list is still empty. Finally, load the first Excel file into the workbook class object that will act as a destination file, load each of the remaining files one-by-one into the Workbook class object and merge to the first Excel file using the Combine method.
Code to Combine Excel Documents using C#
This code has demonstrated the process to merge XLSX files using C#. You may load other types of files also that are supported by the Workbook class. Filter can also be applied to the sheet level so that only the target sheets are loaded for a Workbook and then merge into the destination Excel file.
This article has taught us the process to combine Excel files. To create a Gantt chart in an Excel file, refer to the article Create Gantt Chart in Excel using C#.