excel作为网站服务器,Excel工作表作为C#后端服务器的前端

我做了一个快速博士。谷歌搜索的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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值