Excel to various JSON objects

后端 未结 2 925
有刺的猬
有刺的猬 2021-01-16 15:38

I have this Excel table:

country     year    1       2       3       4

Netherlands 1970    3603    4330    5080    5820
Netherlands 1971    3436    4165    4929          


        
相关标签:
2条回答
  • 2021-01-16 16:17

    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

    0 讨论(0)
  • 2021-01-16 16:22

    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

    0 讨论(0)
提交回复
热议问题