Skip to content

Instantly share code, notes, and snippets.

@gpoulter
Created April 10, 2012 11:32
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gpoulter/2350680 to your computer and use it in GitHub Desktop.
Save gpoulter/2350680 to your computer and use it in GitHub Desktop.
Build Freemind MindMap from Excel file
#!/usr/bin/python
"""Convert CSV table to MindMap format
Usage: python csv_to_mm.py sometable.csv > mymap.mm
CSV format is rows representing tree leaves, e.g.:
A1,
A1,B1
A1,B1,C1
A1,B1,C2
A2,B2
Parses into the following tree:
A1
B1
C1
C2
A2
B2
"""
# http://pypi.python.org/pypi/xmlbuilder
from xmlbuilder import XMLBuilder
import csv
import sys
def csv_to_tree(rows):
root = {}
for row in rows:
tree = root
for val in row:
if val == '':
break
if val not in tree:
tree[val] = {}
tree = tree[val]
return root
def tree_to_xml(root):
xml = XMLBuilder('map', version='0.9.0')
def rec_tree(tree, xnode):
if tree == {}:
return
xnode['folded'] = 'true'
for key, subtree in tree.iteritems():
rec_tree(subtree, xnode.node(text=key))
xroot = xml.node(text='Categories')
rec_tree(root, xroot)
xroot['folded'] = 'false'
return str(xml)
def csv_to_mm_file(inpath):
with open(inpath) as instream:
rows = [[v.decode('utf-8') for v in row]
for row in csv.reader(instream)]
print tree_to_xml(csv_to_tree(rows))
if __name__ == "__main__":
csv_to_mm_file(sys.argv[1])
@migangil
Copy link

It doesn't run. I try with a simple csv file and the mm file created is 0 bytes. Probably I'm doing anything wrong, but I don't know what. The Free Mind version is 0.9.0

@garyritchie
Copy link

This worked for me, thanks!

Python27 on Windows 7 with the http://pypi.python.org/pypi/xmlbuilder library installed. Freemind 1.0.0.

@tastytune
Copy link

It worked for me Ubuntu 14.04- freemind 0.9.
My file had you have to remove this line to make it work.
Thanks a lot gpoulter :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment