我正在尝试绑定/使用 vb 中的对象,如 excel.application 等.我主要是一个vb6编码器,现在正在转移和学习vb.
i am trying to bind/use objects in vb like excel.application etc etc. I am mainly a vb6 coder and now shifting and learning vb.
在 vb6 中,我可以通过使用 createobject 函数轻松处理
in vb6 i can easily handle that by using createobject function
这是vb6代码:
Dim objXLS As Object Dim objWorkBook As Object Set objXLS = CreateObject("Excel.Application") objXLS.Visible = False Set objWorkBook = objXLS.Workbooks.Open("Excel File Goes Here") objWorkBook.SaveAs strCurPath & "\Temp.csv", 6 objWorkBook.Close 2 objXLS.Quit Set objWorkBook = Nothing Set objXLS = Nothing我查看了互联网并找到了以下适用于 c# 但不适用于 的解决方案.我未能在 vb 中使用动态类型/命令.
i have looked over internet and found below solution for c# but not for . and i failed to use dynamic type/command with vb.
这是链接:
C#中CreateObject的等效代码
也有杂乱的方法..但我喜欢用简单的方法(标签绑定左右)
there is also messy way.. but i like to go with the easy way (label binding or so)
那么,有没有办法在 vb 中使用动态密钥,或者 vb 中的等价物是什么?
so, is the any way to use dynamic key to use in vb or what is the Equivalent in vb?
推荐答案VB.Net 方式,无需后期绑定,因为您可以直接从库中创建对象.使用 Marshal 类清理它们,因为它是一个 COM 对象 - 以相反的顺序.
VB.Net way, no late binding as you can create the objects directly from the library. Clean them up with the Marshal class since in it a COM object - in reverse order.
Dim objXLS As New Excel.Application Dim objWorkBook As Excel.Workbook = objXLS.Workbooks.Open("Excel File Goes Here") objXLS.Visible = False 'work with file objWorkBook.SaveAs strCurPath & "\Temp.csv", 6 objWorkBook.Close 2 objXLS.Quit Marshall.FinalReleaseComObject(objWorkBook) Marshall.FinalReleaseComObject(objXLS)更多推荐
VB.net中CreateObject的等效代码
发布评论