VB.net中CreateObject的等效代码 [英] Equivalent code of CreateObject in VB.net

查看:86
本文介绍了VB.net中CreateObject的等效代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绑定/使用 vb.net 中的对象,如 excel.application 等.我主要是一个vb6编码器,现在正在转移和学习vb.net.

i am trying to bind/use objects in vb.net like excel.application etc etc. I am mainly a vb6 coder and now shifting and learning vb.net.

在 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# 但不适用于 .net 的解决方案.我未能在 vb.net 中使用动态类型/命令.

i have looked over internet and found below solution for c# but not for .net. and i failed to use dynamic type/command with vb.net.

这是链接:

C#中CreateObject的等效代码

也有杂乱的方法..但我喜欢用简单的方法(标签绑定左右)

there is also messy way.. but i like to go with the easy way (label binding or so)

那么,有没有办法在 vb.net 中使用动态密钥,或者 vb.net 中的等价物是什么?

so, is the any way to use dynamic key to use in vb.net or what is the Equivalent in vb.net?

推荐答案

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的等效代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆