Excel到各种JSON对象

我有这个Excel表格:

国家年1 2 3 4

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

我想尝试两种JSON格式。 或者:

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

或者使用标头1,2,3,4作为x值:

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

我如何轻松地从Excel中获取我的首选JSON格式?

请提出具体的转换方法,以及通用的数据转换工具,如优秀的Mr Data Converter和Google Refine 。

谢谢!

您可以从这里下载一组将Excel数据转换为JSON的类。 http://ramblings.mcpher.com/Home/excelquirks/downloadlist 。 你想要的项目是“数据操作类”。

使用这些类,这个代码

 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 

是从你的数据产生这一切所需要的。

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

阅读本文后,你可以做更复杂的事情,或者定制输出。 http://ramblings.mcpher.com/Home/excelquirks/recursionlink/hiding-data-in-excel-objects

布鲁斯

我有时只是使用简单的stringconcatanation生成SQL语句,猜你可以做这样的事情:

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

比它包装在data = [] ,或使用一个奇特的公式..对于第二部分,你应该locking$ A1的行