我做了一个快速博士。谷歌搜索的WebService从Excel电话,发现如下article
Option Explicit
' Excel VBA Function wrapper to call currency conversion Web Service on the web!
Public Function ccyConvert(rsCurrIn As String, rsCurrOut As String,
ByVal vfAmtIn As Single) As Single
Dim objSClient As MSSOAPLib30.SoapClient30
' Remove the 30 if using an earlier version of SOAP
Dim fResult As Single
' Point the SOAP API to the web service that we want to call...
Set objSClient = New SoapClient30
Call objSClient.mssoapinit(
par_WSDLFile:="http://webcontinuum.net/webservices/ccydemo.wsdl")
' Call the web service
fResult = objSClient.calcExcRate(rsCurrIn, rsCurrOut, vfAmtIn)
Set objSClient = Nothing
ccyConvert = fResult
End Function
由于Excel中有可能性访问数据(来自不同数据源)它可能是一个妥善的解决办法,以创建c#的WebService其中提供请求数据。
请注意,这不是我的代码 - 这只是从上述文章的副本 - 所以功劳归于作者!
我刚想过另一种解决方案。您可以考虑制作您自己的C#com组件。在任何excel VBA代码您现在可以调用您的程序集内的任何方法。再次,先生。谷歌发现一个article描述如何实现这一点!对于自己的COM组件
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace DotNetLibrary
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class DotNetClass
{
public DotNetClass()
{
}
public string DotNetMethod(string input)
{
return "Hello " + input;
}
}
}
VBA代码
C#代码 Excel宏
Private Sub TestDotNetCall()
Dim testClass As New DotNetClass
' or do whatever you want with return value
MsgBox testClass.DotNetMethod(“World”)
End Sub