对不起挖了一个旧的文章,但我最近也有类似的约束一切需要被包含到一个工作簿,并要张贴我的解决方案的情况下,任何人有类似的问题。最终编写了我自己的全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