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中的单元格
基础教程推荐
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
