通过 Excel 宏连接到 Cloudant

Connect to Cloudant via Excel Macro

我想从我编写的 Excel 宏连接到 Cloudant 数据库。该宏本质上需要在特定字段中搜索另一个字段中的数据。示例:对于 ID="2",字段 "Name" 中的 return 数据。有谁知道这是怎么可能的?

谢谢。

编辑: 我已经发布了我自己的问题的答案。我发布的答案从指定的数据库中获取所有文档。从这里你可以通过查询等方式得到你要找的具体数据。您还可以使用 excel 宏 JSON 解析器,发现 here to help sort through the data. The Base64Encoder I used can be found here.

From the documentation:

All requests to Cloudant go over the web, which means any system that can speak to the web, can speak to Cloudant. All language-specific libraries for Cloudant are really just wrappers that provide some convenience and linguistic niceties to help you work with a simple API.

现在,回答你的问题:

Does anyone know if/how this is possible?

VBA 能够发送和接收 HTTP 请求,因此,使用 Excel(或任何其他可以 运行 VBA 的应用程序)是可能的。

万一有人搜索过这个,我想我会上传对这个问题的实际回答(将近一个月后),而不仅仅是 "yes, this is possible"。

由于 Cloudant 需要基本身份验证,因此我发现执行此操作的方法如下:

Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
Dim response As String
    'Sameple URL: https://ibmcds.cloudant.com/sandbox/_all_docs
URL = "https://" + CloudantUsername + ".cloudant.com/" + DatabaseName + "/_all_docs"
With objHTTP
    .Open "GET", URL, False
    .SetRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
    .SetRequestHeader "Content-Type", "application/json"
    .SetRequestHeader "Accept", "application/json"
    .SetRequestHeader "Authorization", "Basic " + Base64Encode(CloudantUsername + ":" + CloudantPassword)
    .Send ("")
End With
response = objHTTP.responseText

在此示例中,Base64Encode 函数仅对给定的字符串进行编码。您可以为此使用任何 Base64 编码器。

如果您想查看请求的状态,您可以使用:

If objHTTP.Status = 200 Then
    response = objHTTP.responseText
    MsgBox "This request is valid.", vbOKOnly
Else
    MsgBox "This request is not valid.", vbOKOnly
End If

或类似的东西。

我希望这对任何可能想要做类似事情的人有所帮助。