Download Spire.XLS, make sure Spire.XLS and Visual Studio are correctly installed on system. Follow the guide below to merge Excel files.
Create a C#/VB.NET project in your visual studio. Add Spire.XLS.dll as reference. The default setting of Spire.Xls.dll is placed under "C:\Program Files\e-iceblue\Spire.Xls\Bin”. Select assembly Spire.Xls.dll and click OK to add it to the project.
static void Main(string args)
Put the Excel files which need be merged together into the project folder. Use the code below to load the Excel files into the project.
//load the first workbook
Workbook workbook = new Workbook();
//load the second workbook
Workbook workbook2 = new Workbook();workbook2.LoadFromFile(@"..\..\country.xls", ExcelVersion.Version97to2003);
Insert the content of Excel files into the first Excel file by using the following code.
//insert the second workbook's worksheet into the first workbook using a dataTable
Worksheet sheet2 = workbook2.Worksheets;
DataTable dataTable = sheet2.ExportDataTable();
Worksheet sheetAdd = workbook.CreateEmptySheet("Country");sheetAdd.InsertDataTable(dataTable, true, 1, 1);
After finish merging Excel files, save the modified Excel file as .xls format. And we can preview what we’ve done by pressing F5 to launch the project.
//save the workbook
//launch the workbook
Spire.XLS is a professional Excel component which enables developers/programmers to fast generate, read, write and modify Excel document for .NET and Silverlight. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight. Click to learn more...