【问题标题】:Connect Excel to CouchDB将 Excel 连接到 CouchDB
【发布时间】:2021-07-01 15:25:57
【问题描述】:

我正在尝试从 CouchDB 数据库中检索一些数据并将它们显示在 Excel 工作表中。

我发现了一个相当老的线程here,PowerQuery 仍然是最佳选择吗?

【问题讨论】:

    标签: excel couchdb


    【解决方案1】:

    您可以使用 VBA 和基本身份验证。

    例子:

    Public Sub getDataFromCouchdb()
        Dim objHTTP As Object, JSON As Object
        Set objHTTP = CreateObject("Microsoft.XmlHttp")
        
        user = "username"
        pass = "password"
        
        URL = "https://examples.com:5984/dbname/doc_id"
        objHTTP.Open "GET", URL, False
        objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
        objHTTP.setRequestHeader "Content-Type", "application/json; charset=utf-8"
        objHTTP.setRequestHeader "Authorization", "Basic " + Base64Encode(user + ":" + pass)
        
        objHTTP.send ("")
        
        Debug.Print objHTTP.responseText
        Sheets("Plan1").Cells(10, 10).Value = objHTTP.responseText
        
        Set JSON = JsonConverter.ParseJson(objHTTP.responseText)
        Debug.Print JSON("_id")
        Sheets("Plan1").Cells(10, 11).Value = JSON("_id")
    
    End Sub
    

    要解析 JSON,你可以使用这个库:

    https://github.com/VBA-tools/VBA-JSON

    需要这个其他库:

    https://github.com/VBA-tools/VBA-Dictionary

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-29
      • 2011-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-28
      相关资源
      最近更新 更多