You can try free spire.xls to merge excel files into one without connecting to database.
First, install free spire.xls via
nuget. Second, try below code to merge mutiple excel files into a single excel file in c#, remember to add needed namespaces.
Workbook newbook = new Workbook();
newbook.Version = ExcelVersion.Version2013;
newbook.Worksheets.Clear();
Workbook tempbook = new Workbook();
string[] excelFiles = new String[] { "sample1.xlsx", "sample2.xlsx", "sample3.xlsx" };
for (int i = 0; i < excelFiles.Length; i++)
{
tempbook.LoadFromFile(excelFiles[i]);
foreach (Worksheet sheet in tempbook.Worksheets)
{
newbook.Worksheets.AddCopy(sheet);
}
}
newbook.SaveToFile("result.xlsx", ExcelVersion.Version2013);
For more info check this
link. Apart from merging to a single excel file, you can also merge excel files into a single worksheet by simply invoking
Worksheet.ExportDataTable and Worksheet.InsertDataTable methods.
Member
50 Points
37 Posts
Re: How to read multiple excel files and export them into another excel by C#
Mar 12, 2020 07:52 AM|Leon Davis|LINK
Hi,
You can try free spire.xls to merge excel files into one without connecting to database.
First, install free spire.xls via nuget. Second, try below code to merge mutiple excel files into a single excel file in c#, remember to add needed namespaces.
For more info check this link. Apart from merging to a single excel file, you can also merge excel files into a single worksheet by simply invoking Worksheet.ExportDataTable and Worksheet.InsertDataTable methods.
Hope it helps.