How to copy excel worksheets Into another excel workbook without opening the excel file in c# winforms? -


in c# windows application, have many excel workbooks, want copy worksheets excel workbook single workbook. possible, have open excel workbooks in order so.

        excel.application app = new excel.application();          app.visible = true;          app.windowstate = xlwindowstate.xlminimized;          app.workbooks.add("");         app.workbooks.add(@"path\workbook1.xlsx");         app.workbooks.add(@"path\workbook2.xlsx");          (int = 2; <= app.workbooks.count; i++)         {             int count = app.workbooks[i].worksheets.count;              app.workbooks[i].activate();             (int j = 1; j <= count; j++)             {                 excel._worksheet ws = (excel._worksheet)app.workbooks[i].worksheets[j];                  ws.select(true);                 ws.cells.select();                  excel.range sel = (excel.range)app.selection;                 sel.copy(type.missing);                  excel._worksheet sheet = (excel._worksheet)app.workbooks[1].worksheets.add(                     type.missing, type.missing, type.missing, type.missing                     );                  sheet.paste(type.missing, type.missing);                  sheet.name = app.workbooks[i].worksheets[j].name;             }           }          app.displayalerts = false;         app.workbooks[3].close();         app.workbooks[2].close();         app.displayalerts = true;          cursor = cursors.default;          messagebox.show("successfully generated excel...!", "excel tool", messageboxbuttons.ok, messageboxicon.information); 

is possible without opening excel sheets, copy data styles ?

to copy worksheet , contents , formatting without selecting , copying contents of worksheet can make use of worksheet.copy. you'd use so:

excel._worksheet ws = (excel._worksheet)app.workbooks[i].worksheets[j]; excel._worksheet sheet = (excel._worksheet)app.workbooks[1].worksheets.add(                 type.missing, type.missing, type.missing, type.missing                 ); ws.copy(before: sheet); 

if, however, mean question want copy contents of workbooks 1 common workbook without ever opening file, don't believe that's possible. need open file access data.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -