Excel工作表作为C#后端服务器的前端

我有一个C#馈线,生成一些数据,并将其发送到某种前端。 有没有一种直接的方式可以使用excel microsoft office来接收这些数据? PS我不想写一个代码接收数据,然后写入Excel表。 我希望能够直接从excel本身获取数据,作为我的C#后端的前端。 这有可能吗?!

我做了一个快速的博士。 谷歌search来自Excel的WebService调用,并find以下文章

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有可能访问数据(来自不同的数据源),因此创build一个交付 所需数据的 ac#WebService可能是一个合适的解决scheme。

请注意, 这不是我的代码 – 这只是从提到的文章的副本 – 所以功劳归于作者!

我只是想了解另一个解决scheme。 您可以考虑制作自己的C#com组件 。 在任何Excel VBA代码中,你现在可以调用你的程序集中的任何方法 。 再一次先生。 谷歌发现一篇文章描述如何实现这一点!

你自己的COM组件的C#代码

 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; } } } 

Excelmacros中的VBA代码

 Private Sub TestDotNetCall() Dim testClass As New DotNetClass ' or do whatever you want with return value MsgBox testClass.DotNetMethod(“World”) End Sub