【问题标题】:Using Excel to pull data from API使用 Excel 从 API 中提取数据
【发布时间】:2015-02-07 00:11:16
【问题描述】:

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

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

你能告诉我应该怎么做吗?或者请您提供示例代码。

非常感谢

【问题讨论】:

  • 包含您迄今为止所做的一些工作将帮助其他人为其提供建议的起点。
  • 查克,公平点 - 不幸的是,我仍在想办法开始

标签: json excel rest asp.net-web-api


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    首先选择一种语言。如果你是编程新手,可以试试Python。开始并不难。只需关注good Getting Started Guide

    然后找到连接到系统所需的库。例如:

    尝试基本的东西(API 上的简单 GET,Excel 文档中的简单写入)。让它起作用。迭代。

    【讨论】:

      猜你喜欢
      • 2018-02-16
      • 2021-01-12
      • 2014-08-09
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      • 2021-10-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多