Merging data from two spreadsheet files is not a difficult task in Excel but what about if you have to combine files in large numbers? Don’t think to do it manually, just automate it. Combining two or more spreadsheets into a single one is just a job of a few lines of code. This article discusses ways how to merge Excel files and spreadsheets into a single one using C#. Further, it will also show how you can join specific sheets of different files using a similar C# code.
The following topics are covered in this article:
- .NET API to Merge Excel Files
- Merge Excel Files and Spreadsheets
- Merge Specific Sheets of Multiple Excel files
.NET API to Merge Excel Files
GroupDocs provides high-code document automation APIs for merging similar and multiple types of documents. Along with merging multiple Excel files, it allows splitting documents, moving certain pages, and removing, swapping, or extracting pages from various documents using very less code.
The examples in this article use GroupDocs.Merger for .NET. Before you proceed, you better set the environment to use the API from either of the following options:
- Install or Update the package from NuGet Packages Gallery.
- Download the MSI or DLLs from the downloads section.
How to Merge Excel Files and Spreadsheets using C#
If two spreadsheets have the same or similar records, you might be thinking to merge such files to avoid switching between files and to reduce workload and confusion. The following steps show how to combine Excel files (XLS or XLSX) within the .NET application using C#.
- Load the first Excel spreadsheet using the Merger class.
- Combine the second spreadsheet using the Join method.
- Keep joining more spreadsheets using the same Join method.
- Save the merged spreadsheet output file using the Save method.
The following C# code snippet merges multiple Excel spreadsheets.
How to Merge Specific Sheets of Multiple Excel files using C#
Spreadsheet merging should not be limited to just combining the whole spreadsheet. You can also merge specific sheets of your choice from the multiple Excel spreadsheet files. The following steps show how to merge specific sheets using C#.
- Load the first Excel file using the Merger class.
- Select the sheets to join using the JoinOptions class.
- Now, combine both sets of spreadsheets using the Join method along with the prepared join options.
- Save the merged spreadsheets into a separate file using the Save method.
The following C# code snippet combines the selected spreadsheets of the multiple Excel files.
Free API License
You can get a free temporary license and merge your Excel files data without evaluation limitations.
To conclude, today we discussed how to merge two or more Excel spreadsheets using C# within the .NET application. More specifically we combined whole Excel spreadsheet files and then merged a few selected sheets from multiple files. You can use this document merging feature within your .NET applications to combine multiple Excel files and chosen spreadsheets online.
Learn More & Get in Touch
Contact us on the forum about any queries.