Given the following as the contents of the first sheet of an xlsx roi.xlsx:
Then:
wb = load_workbook('roi.xlsx', data_only=True)
ws=wb.worksheets[0]
keynames = [i.value for i in ws.columns[0]]
I want to add values into column B from the following dict:
mydict = {'carnival': 2, 'festival': 3}
When I try:
for k, v in mydict.items():
keyPosition = keynames.index(k)
ws.cell(row = keyPosition, column = 2).value = v
I end up with a new column B, but empty values throughout, AND when I go to re-open the file after saving it with wb.save, Excel can't open the file because it is corrupted.