解析器转换.NET字典或列表VBA等效字典或集合 [英] parser to convert .net dictionary or list to VBA's equivalent dictionary or collection

查看:274
本文介绍了解析器转换.NET字典或列表VBA等效字典或集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有对象的.NET字典或列表类型传递给VBA。
,但是当我传递的.NET字典,VBA侧我不能够看到的字典在.NET上侧的元素。

i have to pass the .net dictionary or list type of object to VBA. but when i am passing the .net dictionary at VBA side i am not able to see the elements of dictionary on .net side.

我在C#代码

Dictionary<string,object> dict = new Dictionary<string,object>();
dict.Add("First", "1");
dict.Add("Second", "2");
dict.Add("third", "3");
dict.Add("Forth", "4");



我打电话从C#VBA宏为

i am calling the VBA macro from C# as

Application.Run("MyVBAMacro", dict);

在VBA的我的宏是

public Sub MyVBAMacro(var as variant)

end Sub

我也试图与

public Sub MyVBAMacro(var as Scripting.Dictionary)

end Sub

但对我没有工作。

在VBA的WATCH窗口我没有得到的字典元素。

in the WATCH window of VBA i am not getting the dictionary elements.

所以,我认为.NET和VBA对象是不一样的。
那么,有没有解析类由我能否将.NET对象转换为相当于VBA对象?

so i think .net and VBA objects are not same. so is there any parsing class by which i can convert my .net objects to equivalent VBA objects?

问题也是与.NET List对象。
.NET阵列工作正常,但我想通过对象VBA的字典或集合类型。

problem is also with the .net List object. .net array is working fine but i want to pass dictionary or collection type of objects to VBA.

请让我知道如果有一些解决这个

please let me know if there is some solution to this.

谢谢,
Monil Gangar

Thanks, Monil Gangar

推荐答案

您需要VBA和.NET $ b $之间的互操作做当b这是一个简单的开始使用COM:的 COM互操作

You need to use COM when doing interop between VBA and .NET This is a simple start: COM Interop

但它可以得到多一点错综复杂的很快,我建议你阅读了关于一般COM的话题,编组,引用计数和开展此类工作时,类型库。

But it can get a bit more intricate quite quickly, i'd recommend reading up on the topics of general COM, marshaling, reference counting and type libraries when undertaking such a task.

制作的简单例子字典COM可见

Simple example for making that dictionary COM Visible

[ComVisible(true)]
public interface IDictWrapper
{
    object GetByKey(string key);
}

[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ComDefaultInterface(typeof(IDictWrapper))]
public class DictWrapper: Dictionary<string,object>, IDictWrapper
{
    public object GetByKey(string key)
    {
        return base[key];
    }
}

这篇关于解析器转换.NET字典或列表VBA等效字典或集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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