1

嗨,我在一个网页上有一个 Json 响应,我试图用该数据捕获更新现有电子表格。我已经使用以下 VBScript 进行了引用。我得到一个空白的 excel,不知何故电子表格没有收到 json 数据

网页上的 JSON 响应

[
    {
        "Sno ": "1",
        "Name": "Alex",
        "Age ": "27",
        "City": "Newyork"
    },
    {
        "Sno ": "2",
        "Name": "Smith",
        "Age ": "25",
        "City": "Los angeles"
    },
    {
        "Sno ": "3",
        "Name": "austin",
        "Age ": "26",
        "City": "Calfornia"
    }
]

正在使用 VBScript(从堆栈源链接引用它)

Sub Button4_Click()    
    'clearing the contents of the sheet prior to synchronisation of data with GCP
    Dim str As String
     Dim myarray() As Variant
    'Delete existing data
    Sheets("Backup_sheet").Activate 'Name of sheet the data will be downloaded into. Change as required.
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents

    Url = "http://127.0.0.1:5555/refresh"
    Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    objHTTP.Open "GET", Url, False, "john", "hello"
    objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
    objHTTP.setRequestHeader "Content-Type", "application/json"

    QueryQuote:
                With Sheets("Backup_sheet").QueryTables.Add(Connection:="Url;" & str, Destination:=Sheets("Backup_sheet").Range("a1"))
                    .BackgroundQuery = True
                    .TablesOnlyFromHTML = False
                    .Refresh BackgroundQuery:=False
                    .SaveData = True
                End With
    Sheets("Backup_sheet").Range("a1").CurrentRegion.TextToColumns Destination:=Sheets("Backup_sheet").Range("a1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=False, Comma:=True, Space:=False, other:=True, OtherChar:=",", FieldInfo:=Array(1, 2)

    Sheets("Backup_sheet").Columns("A:B").ColumnWidth = 12
    Range("A1").Select
End Sub

获取数据后的预期输出

在此处输入图像描述

有人可以在我弄错的地方提供帮助/任何建议如何实现这一点都会有所帮助。谢谢你。

4

0 回答 0