使用Excel从API中提取数据

sCi*_*ion 2 rest excel json asp.net-web-api

在编码方面我是一个完全的新手,非常感谢您在项目中的帮助。

我想从网站提供的 API 中提取 Excel 中的数据(资源 URL: http: //api.opensignal.com/v2/networkrank.json)。

你能建议我该怎么做吗?或者您可以帮忙提供示例代码吗?

非常感谢

Tim*_*all 5

我制作了VBA-Web (Excel-REST),用于使用 Excel 访问 Web 服务和 API。虽然我鼓励您研究有关如何使用 Excel 执行 Web 请求的教程(查找 XMLHTTPRequest),但我发现入门有点棘手,特别是如果您是编程新手,因此这里有一些示例基于OpenSignal 示例的代码:

Sub GetNetworkRank(Latitude As Double, Longitude As Double)
    ' Create client for executing requests
    Dim Client As New WebClient
    Client.BaseUrl = "http://api.opensignal.com/v1/"

    ' Create specific request
    Dim Request As New WebRequest
    Request.Resource = "networkrank.json"
    ' Request.Method = WebMethod.HttpGet is default
    ' Request.Format = WebFormat.Json is default

    Request.AddQuerystringParam "lat", Latitude
    Request.AddQuerystringParam "lng", Longitude

    ' distance=20 -> 20 km around lat-lng -> 40km x 40km bounding box
    Request.AddQuerystringParam "distance", 20

    ' network_id=3 -> 3G networks
    Request.AddQuerystringParam "network_id", 3

    Request.AddQuerystringParam "apikey", "YOUR_API_KEY"

    ' Get response from request
    Set Response = Client.Execute(Request)
    ' -> GET http://api.opensignal.com/v1/networkrank.json?lat=...&lng=...&...

    If Response.StatusCode = 200 Then
        ' Get network rank
        ' (json response is automatically parsed)
        Response.Data("networkRank")("...")
    Else
        Debug.Print "Error: " & Response.StatusCode & " " & Response.Content
    End If
End Sub
Run Code Online (Sandbox Code Playgroud)