對不起挖了一箇舊的文章,但我最近也有類似的約束一切需要被包含到一個工作簿,並要張貼我的解決方案的情況下,任何人有類似的問題。最終編寫了我自己的全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
燁......正如我所說,這個解決方案給我留下的install.exe,一堆DLL和VSTO擴展文件。我想只有一個xlsx文件。但感謝您的期待。 – mlusiak 2010-12-22 14:12:19