VB.net中CreateObject的等效代码

编程入门 行业动态 更新时间:2024-10-28 22:26:03
本文介绍了VB中CreateObject的等效代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试绑定/使用 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的等效代码

本文发布于:2023-11-10 18:50:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1576161.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   VB   net   CreateObject

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!