Copy cells in excel using C#(使用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中的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用C#复制excel中的单元格


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 输入按键事件处理程序 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01