from pyexcel_ods import get_data import sys import xml.etree.cElementTree as ET def process_line(field_names, line, root): """ """ if(len(line) <= 0): return "" line_dict = dict(enumerate(line)) xml_line_node = ET.SubElement(root, "entry") for field_index in range(len(field_names)): # Python lists do not have a safe get. # Converting it to a dict to get this safe get. ET.SubElement(xml_line_node, field_names[field_index]).text = \ str(line_dict.get(field_index,"")) if __name__ == '__main__': spreadsheet_path = sys.argv[1] out_path = sys.argv[2] table = get_data(spreadsheet_path)['Sheet1'] root = ET.Element("root") for line in table[1:]: process_line(table[0], line, root) tree = ET.ElementTree(root) tree.write(out_path, encoding="utf8")