Click here to Skip to main content
15,922,309 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an application where i'm keeping multiple excels in a folder. Each excel will have only one sheet. I need to merge these together to single one.

For eg,

Excel 1 having sheet 1 with Header
Header 1 Header 2 Header 3

And data
1 2 3
11 22 33

Excel 2 woth sheet 1 having content
Header 1 Header 4 Header 5
33 44 55
66 77 88

I need a new excel with one sheet and data as follows

Header 1 header 2 Header 3 Header 4 Header 5
1 2 3
11 22 33
33 44 55
66 77 88

I tried one code from the below link[^]

It is giving single file with two sheets having data of excel1 in sheet1 and excel 2 in sheet 2
Updated 9-Sep-13 19:47pm
Sergey Alexandrovich Kryukov 10-Sep-13 1:43am    
No, this is not urgent at all, I can guarantee that. :-)
Will you explain to us, what does it mean, "multiple excels"?
Member 10112611 10-Sep-13 1:44am    
more than one excel file into one excel file
Dholakiya Ankit 10-Sep-13 1:47am    
wrong multiple excells in to 1?
Member 10112611 10-Sep-13 1:49am    
Please read my question..I emntioned my requirement in one example. with excel sheet1 and excel sheet 2
i need to get excel3 with the data in 1 and 2 sheet combined
Dholakiya Ankit 10-Sep-13 1:53am    
so what's the issue you can select both excel in to diff datatable's then combine them into one datatable then write to excel or you can directly write using both datatables the first you have to do is do something..........

Share this answer
I tried the below code to write from datatable to excel

string filename = "Reconciliation_Result.xls";
System.IO.StringWriter tw = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
DataGrid dgGrid = new DataGrid();
dgGrid.DataSource = dt;

//Get the HTML for the control.
//Write the HTML back to the browser.

Response.ContentType = "application/ms-excel";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename + "");
Response.Charset = "utf-8";
Response.ContentEncoding = System.Text.Encoding.GetEncoding("windows-1250");
Response.Write("<Table border='1' bgColor='#ffffff' " +      "borderColor='#000000' cellSpacing='0' cellPadding='0' " +      "style='font-size:10.0pt; font-family:Calibri; background:white;'> <TR>");
this.EnableViewState = true;

it is working ..but the second column of the excel i need to format the second column as text ..can anyone help?
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900