Why is the iteration over this loop not adding cells in openpyxl?

后端 未结 1 1580
迷失自我
迷失自我 2021-01-23 15:27

Given the following as the contents of the first sheet of an xlsx roi.xlsx:

\"enter

<
相关标签:
1条回答
  • 2021-01-23 16:11

    I think the issue is that you are using the index of keynames to store in the B column, index starts at 0 , but column B does not have any 0 row. You should ideally be getting - openpyxl.utils.exceptions.CellCoordinatesException: There is no row 0 (B0)

    Try this code instead (to start changing values at row 1,instead of 0) -

    for k, v in mydict.items():
        keyPosition = keynames.index(k)
        ws.cell(row = keyPosition + 1, column = 2).value = v
    
    0 讨论(0)
提交回复
热议问题