2010-12-22 38 views
2

我想一些數據讀取到來自web服務我的Excel電子表格(Excel 2007中),但我想部署電子表格作爲一個文件只(FE spreadsheet.xlsx - 僅此而已)。消費在Excel Web服務和部署作爲一個文件

如果沒有這個限制,我會用Visual Studio的插件,它在C#寫的,但它會給我一些額外的DLL和VSTO文件。

在Excel的早期版本,還有Web服務Tolkit,但我的研究表明,它不會與2007年

工作是否有任何解決方案在那裏?我聽說過有關Microsoft Office Soap Type library 3.0的一些信息,但我不知道如何開始使用它。

任何幫助/樣本碼/其他解決方案可以理解的。

回答

2

我瞭解如何與Web服務與MS Office SOAP類型庫在VBA連接 - 所以沒有多餘的文件,只是XLS(X)。在這一點上,我知道如何獲得簡單的數據類型結果(如字符串)。但我希望,我能夠獲得並使用更復雜的類型。

下面的代碼:

Dim webservice As SoapClient30 
Dim results As String 

' Point the SOAP API to the web service that we want to call... 
Set webservice = New SoapClient30 
Call webservice.mssoapinit(par_WSDLFile:="{url to wsdl}") 

' Call the web service 
results = webservice.{method name}() 
Set webservice = Nothing 

這是必須加貼「的Microsoft Office SOAP類型庫3.0」到工作表的引用。

1

對不起挖了一箇舊的文章,但我最近也有類似的約束一切需要被包含到一個工作簿,並要張貼我的解決方案的情況下,任何人有類似的問題。最終編寫了我自己的全VBA庫(主要依據我的最愛之一,RestSharp)。

警告,無恥插頭:https://github.com/timhall/Excel-REST

一些有趣的功能,包括認證(HTTP基本,您好!OAuth1和OAuth2用戶客戶端憑證),異步支持和JSON解析(感謝VBA-JSON)

它的工作在Excel 2010中(很可能是2007年)非常棒,但由於缺少XMLHTTP庫,無法在Mac上使用Excel。我找到了與Salesforce,Trello,大本營,谷歌地圖的工作,它應該與幾乎所有的REST Web服務的工作。

例子:

Function GetDirections(Origin As String, Destination As String) As String 
    ' Create a RestClient for executing requests 
    ' and set a base url that all requests will be appended to 
    Dim MapsClient As New RestClient 
    MapsClient.BaseUrl = "https://maps.googleapis.com/maps/api/" 

    ' Create a RestRequest for getting directions 
    Dim DirectionsRequest As New RestRequest 
    DirectionsRequest.Resource = "directions/{format}" 
    DirectionsRequest.Method = httpGET 

    ' Set the request format -> Sets {format} segment, content-types, and parses the response 
    DirectionsRequest.Format = json 

    ' (Alternatively, replace {format} segment directly) 
    DirectionsRequest.AddUrlSegment "format", "json" 

    ' Add parameters to the request (as querystring for GET calls and body otherwise) 
    DirectionsRequest.AddParameter "origin", Origin 
    DirectionsRequest.AddParameter "destination", Destination 

    ' Force parameter as querystring for all requests 
    DirectionsRequest.AddQuerystringParam "sensor", "false" 

    ' => GET https://maps.../api/directions/json?origin=...&destination=...&sensor=false 

    ' Execute the request and work with the response 
    Dim Response As RestResponse 
    Set Response = MapsClient.Execute(DirectionsRequest) 

    If Response.StatusCode = 200 Then 
     ' Work directly with parsed json data 
     Dim Route As Object 
     Set Route = Response.Data("routes")(1)("legs")(1) 

     GetDirections = "It will take " & Route("duration")("text") & _ 
      " to travel " & Route("distance")("text") & _ 
      " from " & Route("start_address") & _ 
      " to " & Route("end_address") 
    Else 
     GetDirections = "Error: " & Response.Content 
    End If 
End Function