|
小弟用C# 生成的DLL 文件,函数返回值为:string 或者数组的时候,在VBA中能正常调用,但返回值为:DataTable 时,可以调用,但只能:call rs.DataReadDataTable ,var =rs.DataReadDataTable 就会报错。
在VBA中不知道怎么调用。
求各位帮助:怎么写,通过VBA代码取到C# DataTable 中的数据,DataTable 其实也就是一张表。
VBA 代码:
Private Sub CommandButton1_Click()
Dim rs As New XmlEvent
Dim var As Variant
var = rs.DataReadDataTable '出错,call rs.DataReadDataTable 没有错误提示
End Sub
C#代码:
using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Runtime.InteropServices;
using System.Collections;
using System.Data;
namespace Common
{
[Guid("694C1820-04B6-4988-928F-FD858B95C880")]
/**/
/// <summary>
/// XML生成
/// </summary>
public interface XmlEvent_Interface
{
[DispId(1)]
int DataWrite(String filePath, String serviceID, ref String[] tag);
[DispId(2)]
String[,] DataRead(String filePath);
[DispId(3)]
System.DataTable DataReadDataTable();//如果为:String,则可以正常调用
}
// Events interface Database_COMObjectEvents
[Guid("47C976E0-C208-4740-AC42-41212D3C34F0"),
InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface XmlEvent_Events
{
}
[Guid("9E5E5FB2-219D-4ee7-AB27-E4DBED8E123E"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(XmlEvent_Events))]
/**/
/// <summary>
/// XML生成
/// </summary>
public class XmlEvent : XmlEvent_Interface
{
public XmlEvent()
{
}
public int DataWrite(String filePath, String serviceID, ref String[] tag)
{
//Do Something;
return 1000;
}
public String[,] DataRead(String filePath)
{
//Do Something;
string[,] s = new string[,] { { "A", "ABC****-****123" },
{ "B", "ABC1****-****1232" },
{ "C", "www1****-****2ggg" },
{ "D", "1ggg****-****2ggg" }
};
return s;
}
public System.DataTable DataReadDataTable()//如果为:String,则可以正常调用
{
DataTable dt = new DataTable("Table_AX");
dt.Columns.Add("column0", System.Type.GetType("System.String"));
DataColumn dc = new DataColumn("column1", System.Type.GetType("System.Boolean"));
dt.Columns.Add(dc);
DataRow dr = dt.NewRow();
dr["column0"] = "AX";
dr["column1"] = true;
dt.Rows.Add(dr);
return dt;
}
}
}
|
|