I have an excel file, which contains two sheets, one contains the nodes and the second the links to build a d3.js force layout diagram.
For the output json file, I want keep the column headings as the key for each item.
and put null for nonexistant data.
In the links part of the json, I prefer to take the id of the topicA and topicB from the nodes instead of putting the string name for the topic.
Regarding the keywords, as they are separated by a comma under the keywords heading, I want to put them into this format "keywords": ["one","two","three"]
. How can this be done in php?
structure of th the nodes
sheet:
id topic number file keywords kind
1 animals 120 file1
2 flowers 500 file2 one,two,three, kind1
3 nature 10 file3 one kind2
4 humans 400 file4 three,two
5 colors 800 file5
structure of the links
sheet:
id topicA topicB relation
1 animals nature 15
2 flowers animals 7
3 flowers nature 3
4 nature colors 1
5 colors humans 2
6 humans flowers 9
7 humans nature 11
the desired output json:
{
"nodes": [{
"topic": "animals",
"number": 120
"file": "file1",
"keywords": null,
"kind": null
},
{
"topic": "flowers",
"number": 500
"file": "file2",
"keywords": ["one","two","three"],
"kind": "kind1"
},
...
],
"links": [{
"topicA": 1,
"topicB": 3,
"relation": 15,
"id": 1
},
...
]
}