Copy cells in excel using c #

How to copy to a specific row in the target sheet?

I need to copy A1 to J10 from a sheet in one excel to a location starting with A15 in a second excel sheet. How can I achieve this in C #? In the copy method below, there seems to be no way to specify the location in the excel target sheet.

ObjWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ObjWorkBookTemp.Sheets[1]; ObjWorkSheet.Copy(Type.Missing, ObjWorkBookGeneral.Sheets[1]); 
+7
source share
1 answer

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

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

Something like that...

 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); 
+9
source

All Articles