从Excel VBA发送阵列数据WCF [英] Sending array data from excel VBA to WCF
问题描述
我的问题是,我想送从VBA字符串数组来WCF。
My problem is, I want to send an array of strings from VBA to WCF.
C#code是:
[OperationContract]
void SetSomeObjects(string[] data);
下面是VBA部分
Dim data(2) As String
data(0) = "abc"
data(1) = "def"
Dim service2 As Object
Set service2 = GetObject(ServiceBindingInformation)
service2.SetSomeObjects data
最后一行抛出VBA
The last line throws VBA
"Type Mismatch Error"
我不知道为什么会这样。请提出一个方法来从VBA发送阵列数据WCF服务 如果我使用的对象作为参数类型,它提供了错误的显示在下面的截图
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
推荐答案
我认为这个问题是在C#code。
I think the problem is within C# code.
有一次,我想根据的LINQ(C#)的阵列(VBA)排序。数组传递给UDF于一体的方式的参数传递给函数/方法:
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:
Dim UDF_Array As UDFArrayLinqTest.ArrayLinq
Set UDF_Array = New UDFArrayLinqTest.ArrayLinq
TBL = Array(...)
Range(...) = UDF_Array.ArraySorted(TBL)
在C#中的简单UDF是如下:
The simple UDF in C# was as follow:
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.
这篇关于从Excel VBA发送阵列数据WCF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!