使用C#复制excel中的单元格 [英] Copy cells in excel using C#

查看:113
本文介绍了使用C#复制excel中的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何复制到目标工作表中的特定行?

How to copy to specific row in target sheet?

我需要将 A1 到 J10 从一个 Excel 中的工作表复制到第二个 Excel 工作表中从 A15 开始的位置.如何在 c# 中实现这一点?在下面的 Copy 方法中,似乎没有选项可以指定目标 Excel 表中的位置.

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 achieve this in c#? In the below Copy method there seems to be no option to specify the location in target excel sheet.

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.

试试 Range.PasteSpecial 方法...应该可以解决问题.

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

这样的……

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);

这篇关于使用C#复制excel中的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆