c#:Copy excel workbook to another -


i have written code copy of worksheets new excel file. below c# code, problem named cells missing, , have checked in excel-2010.

c# code:

string strpath=@"c:\newfolder\somexcelfile.xls"; excel.workbook souworkbook = xcel.workbooks.open(strpath); excel.workbook destworkbook = xcel.workbooks.add();  foreach (excel.worksheet wksheet in souworkbook.worksheets) {    wksheet.copy(destworkbook.worksheets[1]); } destworkbook.savecopyas("c:\newfolder\copy.xls"); 

if need copy named cells, use following code sample

sub copy_all_defined_names()    ' loop through of defined names in active    ' workbook.      each x in activeworkbook.names       ' add each defined name active workbook       ' target workbook ("book2.xls" or "book2.xlsm").       ' "x.value" refers cell references       ' defined name points to.       workbooks("book2.xls").names.add name:=x.name, _          refersto:=x.value    next x end sub 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -