Question

I have this Excel table:

country     year    1       2       3       4

Netherlands 1970    3603    4330    5080    5820
Netherlands 1971    3436    4165    4929    5693
Netherlands 1972    3384    4122    4899    5683
Sweden       1970    1479    1963    2520    3132
Sweden       1971    1497    1985    2547    3163
Sweden       1972    1419    1894    2445    3055

I would like to experiment with two JSON formats. Either:

data = [
   Netherlands : {
      1970 : [3603, 4330, 5080, 5820],
      1971 : [...],
   },
   Sweden : {
      1970 : [...]
   },
]

Or using the headers 1,2,3,4 as x-values:

data = [
   Netherlands : {
      1970 : [{x: 1, y: 3603}, {x: 2, y: 4330}, {x: 3, y: 5080}, {x: 4, y: 5820}],
      1971 : [...],
   },
   Sweden : {
      1970 : [...]
   },
]

How do I easily get from Excel to my preferred JSON formats?

Please suggest specific methods for this transformation as well as generic data conversion tools like the excellent Mr Data Converter and Google Refine.

Thank you!

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top