且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用C#复制excel中的单元格

更新时间:2023-02-13 18:00:47

我认为你在这里使用了错误的方法...你想使用粘贴方法而不是复制方法.

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