簡體   English   中英

使用Excel從API中提取數據

[英]Using Excel to pull data from API

在編碼方面,我是一個完整的新手,非常感謝您在項目中的幫助。

我想從網站提供的API中提取Excel中的數據(資源URL: http//api.opensignal.com/v2/networkrank.json )。

你能告訴我應該怎么做。 或者,您可以幫助您提供示例代碼。

非常感謝

我制作了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

首先選擇一個語言。 如果您是編程新手,可以試試Python 開始並不難。 只需按照良好的入門指南

然后找到連接到系統所需的庫。 例如:

嘗試基本的東西(API上的簡單GET,Excel文檔中的簡單寫入)。 讓它起作用。 重復。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM