Last post Apr 20, 2013 07:46 AM by tarwara99
Sep 27, 2011 07:38 AM|tripati_tutu|LINK
For merging of two excel sheet, I am using below code.
using Excel = Microsoft.Office.Interop.Excel;
static void Main(string args)
Excel.Application app = new Excel.Application();
app.Visible = true;
for (int i = 2; i <= app.Workbooks.Count; i++)
int count = app.Workbooks[i].Worksheets.Count;
for (int j=1; j <= count; j++)
Excel._Worksheet ws = (Excel._Worksheet)app.Workbooks[i].Worksheets[j];
Excel.Range sel = (Excel.Range)app.Selection;
Excel._Worksheet sheet = (Excel._Worksheet)app.Workbooks.Worksheets.Add(
Type.Missing, Type.Missing, Type.Missing, Type.Missing
This code is working good for me for merging excel workbook. But at the time of merging I am not getting the excel sheet names. Here I need that when the excel is merging at the same time the sheet names should also go to the merged excel sheet. So please help me out on this. Its urgent. Thanks In Advance...
Sep 27, 2011 09:03 AM|koolprasad|LINK
So need to add new sheet in your EXCEL document. and then merge other two sheet's in it. Right ?
here is code to add new sheet in excel workbook, you define name for it.
Microsoft.Office.Interop.Excel.Application objAPP = null;
Workbook xlWorkbook = null;
Sheets xlSheets = null;
Worksheet xlNewSheet = null;
objAPP = new Microsoft.Office.Interop.Excel.Application();
objAPP.Visible = true;
xlWorkbook = objAPP.Workbooks.Open(fullFilename, 0, false, 5, "", "", false, XlPlatform.xlWindows, "", true, false, 0, true, false, false);
xlSheets = xlWorkbook.Sheets as Sheets;
//add new sheet
xlNewSheet = (Worksheet)xlSheets.Add(xlSheets, Type.Missing, Type.Missing, Type.Missing);
//give name to new worksheet
xlNewSheet.Name = "NewName";
Sep 27, 2011 09:19 AM|tripati_tutu|LINK
Sorry, actually let's say I have two excel workbook that is Excel1 and Excel2
Excel1 have 3 sheets named A, B, and C.
Excel2 have 1 sheet names D.
So after merging of two workbook I have to get a new single workbook which will have sheets like A, B, C, D. Automatically sheet name will come. No need to declare it manual. What ever the I have written in my question that is merging two excel properly
but name is not coming. So I need merge with sheet name.
Waiting for your valuable response...
May 14, 2012 01:05 AM|jeeshen.lee|LINK
It's not asp related but in case you are looking for a tool to merge many files into one, i wrote a VB script that does the job.
Below is the download link:
Apr 20, 2013 07:46 AM|tarwara99|LINK
Hi Tripati, I have created a
macro that will merge all you sheets into one excel file.
This macro can merge 2010, 2007 and 2003 excel version.