Copy cells in excel using C#

前端 未结 1 740
我在风中等你
我在风中等你 2021-01-05 12:01

How to copy to specific row in target sheet?

I need to copy A1 to J10 from a sheet in one excel to location starting from A15 in second excel sheet. How can I achiev

相关标签:
1条回答
  • 2021-01-05 12:09

    I think you are using the wrong method here... you want to use a Paste method not a copy method.

    Try the Range.PasteSpecial method... should do the trick for you.

    Something like this...

    Excel.Range sourceRange = firstWorksheet.get_Range("A1", "J10");
    Excel.Range destinationRange = secondWorksheet.get_Range("A15", "J25");
    
    sourceRange.Copy(Type.Missing);
    destinationRange.PasteSpecial(Microsoft.Office.Interop.Excel.XlPasteType.xlPasteFormulas, Microsoft.Office.Interop.Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false);
    
    0 讨论(0)
提交回复
热议问题