Пример доступа к данным из Excel
Материал из WebHMI Wiki
Версия от 09:03, 17 января 2015; Alexander.kuzmuk (обсуждение | вклад)
Ниже приведен простой пример запроса из Excel к WebHMI API.
Скачать пример Файл:API Example.xlsm
Const URl As String = "http://192.168.0.1/api/event-data/1" Sub xmlHttp() Dim xmlHttp As Object Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0") xmlHttp.Open "GET", URl, False xmlHttp.setRequestHeader "Content-Type", "text/xml" xmlHttp.setRequestHeader "Accept", "application/json" xmlHttp.setRequestHeader "Host", "192.168.0.1" xmlHttp.setRequestHeader "Cookie", " " xmlHttp.setRequestHeader "X-WH-APIKEY", "6E51E728896794EBF406E2F070BE7AFBE49E90D4" xmlHttp.setRequestHeader "X-WH-START", "1388948941" xmlHttp.setRequestHeader "X-WH-END", "1399208143" xmlHttp.send Dim JSON As New JSON Dim p As Object Set p = JSON.parse(xmlHttp.ResponseText) i = 2 j = 1 For Each Item In p ' rows If (j = 1) Then Cells(i, j).NumberFormat = "yyyy-mm-dd hh:mm:ss" End If If (j = 2) Then Cells(i, j).NumberFormat = "#.#" '"$#,##0.00_);[Red]($#,##0.00)" End If For Each Item2 In Item 'columns For Each Item3 In Item2 If (j = 1 And i > 1) Then Cells(i, j) = (Item2(Item3) / 86400) + 25569 Else Cells(i, j) = Item2(Item3) End If Cells(1, j) = Item3 Next j = j + 1 Next i = i + 1 j = 1 Next End Sub