2012-06-21 42 views
1

我有一個C#進紙器,它生成一些數據並將它們發送到某種前端。是否有直接的方式可以使用excel microsoft office來接收這些數據? P.S.我不想編寫接收數據的代碼,然後將它寫入Excel表。我希望能夠直接從excel本身獲取數據,作爲我的C#後端的前端。這是否有可能?!Excel工作表作爲C#後端服務器的前端

+0

內設計的整個前端是有點大了一個SO問題。你能縮小到一個特定的任務嗎?如果您想知道如何從Excel工作表中獲取數據,或者如何將數據保存到XSL/CSV/XML /等。格式,我可以幫助你。 –

回答

1

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

另一種情況是將數據發佈到數據庫中。編寫一個宏來檢索數據應該很容易。 – CodingBarfield