Excel to various JSON objects

半腔热情 提交于 2019-12-01 12:25:30

You can download a set of classes that convert excel data to JSON from here. http://ramblings.mcpher.com/Home/excelquirks/downloadlist. The project you want is 'Data manipulation classes'.

Using these classes, this code

Option Explicit
Public Sub mainExample()
    Dim dSet As cDataSet

    Set dSet = New cDataSet
    With dSet
        .populateData Range("data!$a$1"), , , , , , True

        If .Where Is Nothing Then
            MsgBox ("No data to process")
        Else
            MsgBox .jSonObject
        End If
    End With

End Sub

is all thats needed to produce this from your data.

{  "data": {
        "country": "Sweden",
        "year": "1972",
        "1": "1419",
        "2": "1894",
        "3": "2445",
        "4": "3055"
  }
}

You can do more complex things, or tailor the output, after reading this article on how it works. http://ramblings.mcpher.com/Home/excelquirks/recursionlink/hiding-data-in-excel-objects

bruce

I sometimes just use simple string concatanation to generate SQL Statements, guess you could do something like:

=A2 + ": { " + A3 + ", " + A4 + ", " + A5 + ", " + A... +"}"

Than wrap it inside data = [], or use a fancy formula.. For the second part you should lock the row with $A1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!