close

Guys

I need to copy data from an uploaded excel into master excel . I'm doing
this but the excel objects are not getting cleaned up. I see 2 instances of
Excel running in 'Task Manager'. Whats the best way to copy range of data
from one excel workbook to other workbook. HEre is my code;

Excel.Application srcExcel = new Excel.ApplicationClass();
Excel._Workbook srcWb = srcExcel.Workbooks.Open(fName, Missing.Value,
Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
Excel._Worksheet srcWsh = (Excel._Worksheet)srcWb.Sheets.get_Item(2);

Excel.Application dstExcel = new Excel.ApplicationClass();
Excel._Workbook dstWb = dstExcel.Workbooks.Open(eventdir, Missing.Value,
Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);
Excel._Worksheet dstWsh = (Excel._Worksheet)dstWb.Sheets.get_Item(2);

// following seems to work but excel objects are not getting cleaned up
((Excel.Range)dstWsh.get_Range(quot;C4quot;, quot;N26quot;)).Value2 =
((Excel.Range)srcWsh.get_Range(quot;C4quot;, quot;N26quot;)).Value2;

// this one gives error.
//Excel.Range r1 = (Excel.Range)srcWsh.get_Range(quot;C4:N26quot;, Type.Missing);
//Excel.Range r2 = (Excel.Range)dstWsh.get_Range(quot;C4:N26quot;, Type.Missing);
//r2.Value2 = r1.Value2;
//r1.Copy(r2);

pl help.

thanks

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()