Vb.Net - 将单元格从一个Excel工作表复制到另一个Excel工作表 [英] Vb.Net - Copying cells from from one Excel worksheet to another
本文介绍了Vb.Net - 将单元格从一个Excel工作表复制到另一个Excel工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为这是一个简单的解决方案。只是我花了太长时间试图这样做。
我有一个名为SheetA的工作表,并且有来自A1 ...... D1的标题,例如姓氏,姓氏,部门,年龄
我想将此行复制并粘贴到我在同一地方的其他工作表SheetB中。
这是怎么做的?
This I think is a simple solution. Just that I have spent too long trying to do it.
I have a worksheet named, "SheetA" and have headings from A1....D1 e.g. forename, surname, department, age
I want to copy and paste this line into my other worksheet "SheetB" at the same place.
How is this done?
推荐答案
你这样做:
http://www.techonthenet.com/excel/macros/copy_range.php [ ^ ]
使用后期绑定;)
Using late binding ;)
Dim oExc As Object = Nothing, oWbk As Object = Nothing
Dim oSrcWsh As Object = Nothing, oDstWsh As Object = Nothing
Try
oExc = CreateObject("Excel.Applictaion")
oWbk = oExc.Workbooks.Open("FullPathToWorkbook.xls")
oSrcWsh = oWbk.WorkSheets("Sheet1")
oDstWsh = oWbk.WorkSheets("Sheet2")
oSrcWsh.Range("A1:D1").Copy(oDstWsh.Range("A1"))
oWbk.Save()
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
oSrcWsh = Nothing
oDstWsh = Nothing
oWbk.Close(SaveChanges:=False)
oWbk = Nothing
oExc.Quit()
oExc = Nothing
End Try
这篇关于Vb.Net - 将单元格从一个Excel工作表复制到另一个Excel工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文