[英]Copy cells in excel using C#
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. 我需要将A1到J10从一个excel中的工作表复制到第二个excel工作表中从A15开始的位置。 How can I achieve this in c#?
我怎样才能在c#中实现这一目标? In the below Copy method there seems to be no option to specify the location in target excel sheet.
在下面的复制方法中,似乎没有选项来指定目标Excel工作表中的位置。
ObjWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)ObjWorkBookTemp.Sheets[1];
ObjWorkSheet.Copy(Type.Missing, ObjWorkBookGeneral.Sheets[1]);
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. 尝试使用Range.PasteSpecial方法...应该为你做的伎俩。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.