有没有办法按行和列将电子表格 table 格式转换为 JSON 格式?
Is there a way to convert spreadsheet table to JSON format by rows & columns?
我无法用现有的电子表格填充我的数据库。我的objective就是将这些数据导入到一个react应用中进行详细分析
数据量较大,一万多条如下。
这是电子表格示例。
https://docs.google.com/spreadsheets/d/1gfUnloNzqXXfNi8VzoRXDkwax6pVvlkRPkUqbCQ6AtQ/edit?usp=sharing
我想知道是否可以将它们转换成 JSON 按列和行的格式。
( "n": [
{ "new" : [
"cxtype": "PF,
"name" : "this is a name",
"phonenumber" : "0000000000", "...." ]
},
{ "upgrade" : [
"cxtype": "PF,
"name" : "this is a name",
"phonenumber" : "0000000000", "...." ]
} ....]
)
我想知道是否可以通过JavaScript来完成,但如果有办法,我愿意学习其他语言。
请帮忙。谢谢:)
不幸的是,要求不是很清楚,特别是因为按预期显示的输出无效 JSON 并且与示例输入不那么接近,但希望以下内容可以帮助您方式。
首先,我将 Google 电子表格“导出”到 TSV 文件。这会生成一个 DOS 格式的文件,这就是为什么可能需要一些额外的处理来处理“\r”的原因(例如,如下所示)。
其次,我 运行 jq 带有 -nrR 选项,以及以下 jq 程序:
foreach (inputs|split("\t") | select( all(.[]; . == "" or . == "\r") | not )) as $in (null;
if $in[2] == "CUSTOMER TYPE" then .ready = true | .emit = null
elif $in[2] == null then .ready=false | .emit = null
elif .ready and ($in[1] != "") then (.emit=$in)
else (.ready=false) | .emit = null
end;
select(.emit).emit )
| [.[1,2,5]] as [$key, $cxtype, $name]
| { ($key): { $cxtype, $name }}
这会产生以下输出,与问题中显示的非常接近:
{"NEW":{"cxtype":"pf","name":"this is a name"}}
{"UPGRADE":{"cxtype":"pf","name":"this is a name"}}
{"PA":{"cxtype":"","name":""}}
{"PB":{"cxtype":"","name":""}}
我无法用现有的电子表格填充我的数据库。我的objective就是将这些数据导入到一个react应用中进行详细分析
数据量较大,一万多条如下。
这是电子表格示例。 https://docs.google.com/spreadsheets/d/1gfUnloNzqXXfNi8VzoRXDkwax6pVvlkRPkUqbCQ6AtQ/edit?usp=sharing
我想知道是否可以将它们转换成 JSON 按列和行的格式。
( "n": [
{ "new" : [
"cxtype": "PF,
"name" : "this is a name",
"phonenumber" : "0000000000", "...." ]
},
{ "upgrade" : [
"cxtype": "PF,
"name" : "this is a name",
"phonenumber" : "0000000000", "...." ]
} ....]
)
我想知道是否可以通过JavaScript来完成,但如果有办法,我愿意学习其他语言。
请帮忙。谢谢:)
不幸的是,要求不是很清楚,特别是因为按预期显示的输出无效 JSON 并且与示例输入不那么接近,但希望以下内容可以帮助您方式。
首先,我将 Google 电子表格“导出”到 TSV 文件。这会生成一个 DOS 格式的文件,这就是为什么可能需要一些额外的处理来处理“\r”的原因(例如,如下所示)。
其次,我 运行 jq 带有 -nrR 选项,以及以下 jq 程序:
foreach (inputs|split("\t") | select( all(.[]; . == "" or . == "\r") | not )) as $in (null;
if $in[2] == "CUSTOMER TYPE" then .ready = true | .emit = null
elif $in[2] == null then .ready=false | .emit = null
elif .ready and ($in[1] != "") then (.emit=$in)
else (.ready=false) | .emit = null
end;
select(.emit).emit )
| [.[1,2,5]] as [$key, $cxtype, $name]
| { ($key): { $cxtype, $name }}
这会产生以下输出,与问题中显示的非常接近:
{"NEW":{"cxtype":"pf","name":"this is a name"}}
{"UPGRADE":{"cxtype":"pf","name":"this is a name"}}
{"PA":{"cxtype":"","name":""}}
{"PB":{"cxtype":"","name":""}}