Skip to content

Instantly share code, notes, and snippets.

@thurask
Created February 17, 2019 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thurask/67ccc550d115557f87c1253e2258265b to your computer and use it in GitHub Desktop.
Save thurask/67ccc550d115557f87c1253e2258265b to your computer and use it in GitHub Desktop.
import xml.etree.ElementTree as et
import openpyxl
wb = openpyxl.Workbook()
tree = et.parse("Neia_MoreNamesTuning.xml")
root = tree.getroot()
workzone = root[1][2]
for lang in workzone:
langname = lang[0].text
nametuning = lang[1]
femalefirsts = [x.text for x in nametuning[0]]
lasts = [x.text for x in nametuning[1]]
malefirsts = [x.text for x in nametuning[2]]
wsheet = wb.create_sheet(title=langname)
wsheet["A1"] = langname
wsheet["B1"] = "FEMALE FIRST NAMES"
wsheet["C1"] = "MALE FIRST NAMES"
wsheet["D1"] = "SURNAMES"
worklist = [femalefirsts, malefirsts, lasts]
for idz, val in enumerate(worklist):
for idx, name in enumerate(val):
vname = "<T>{0}</T>".format(name)
wsheet.cell(column=idz+2, row=idx+2, value=vname)
wb.save(filename="name_book.xlsx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment