将数组数据从excel VBA发送到WCF

时间:2023-01-15 13:27:35

My problem is, I want to send an array of strings from VBA to WCF.

我的问题是,我想从VBA向WCF发送一个字符串数组。

c# code is :

c#代码是:

[OperationContract]    
void SetSomeObjects(string[] data);

Here is the VBA Part

这是VBA部分

Dim data(2) As String
data(0) = "abc"
data(1) = "def"

Dim service2 As Object
Set service2 = GetObject(ServiceBindingInformation)
service2.SetSomeObjects data

The last line throws VBA

最后一行抛出VBA

"Type Mismatch Error"

I have no idea why is this happening. Please suggest a way to send array data from VBA to WCF Service If I used object as the argument type, it gives error as shown in the attached screenshot

我不知道为什么会这样。请建议一种从VBA向WCF服务发送数组数据的方法如果我使用object作为参数类型,它会给出错误,如附带的屏幕截图所示

1 个解决方案

#1


0  

I think the problem is within C# code.

我认为问题出在C#代码中。

Once I wanted to sort the array (VBA) based on Linq (C#). Array was passed to UDF in the way one pass an argument to the function/method:

一旦我想基于Linq(C#)对数组(VBA)进行排序。数组以传递函数/方法的方式传递给UDF:

Dim UDF_Array As UDFArrayLinqTest.ArrayLinq
Set UDF_Array = New UDFArrayLinqTest.ArrayLinq

TBL = Array(...)
Range(...) = UDF_Array.ArraySorted(TBL)

The simple UDF in C# was as follow:

C#中的简单UDF如下:

public double[] ArraySorted(object tbl)
    {
        object[] obj = (object[])tbl;
        var filtr = from i in obj
                    orderby Convert.ToDouble(i)
                    select Convert.ToDouble(i);

        double[] result = (double[])filtr.ToArray();
        return result;
    }

I don't think it is the best idea but I stopped searching better one after I did that above which was good enough for me.

我认为这不是最好的主意,但是在我做完之后我就停止了更好的搜索,这对我来说已经足够了。

#1


0  

I think the problem is within C# code.

我认为问题出在C#代码中。

Once I wanted to sort the array (VBA) based on Linq (C#). Array was passed to UDF in the way one pass an argument to the function/method:

一旦我想基于Linq(C#)对数组(VBA)进行排序。数组以传递函数/方法的方式传递给UDF:

Dim UDF_Array As UDFArrayLinqTest.ArrayLinq
Set UDF_Array = New UDFArrayLinqTest.ArrayLinq

TBL = Array(...)
Range(...) = UDF_Array.ArraySorted(TBL)

The simple UDF in C# was as follow:

C#中的简单UDF如下:

public double[] ArraySorted(object tbl)
    {
        object[] obj = (object[])tbl;
        var filtr = from i in obj
                    orderby Convert.ToDouble(i)
                    select Convert.ToDouble(i);

        double[] result = (double[])filtr.ToArray();
        return result;
    }

I don't think it is the best idea but I stopped searching better one after I did that above which was good enough for me.

我认为这不是最好的主意,但是在我做完之后我就停止了更好的搜索,这对我来说已经足够了。