Python - How to use a for loop to write data to a cell, then move to the next row
Question: I have what feels like a problem with a relatively simple solution, but to
this point it escapes my research. I'm attempting to write items from a tuple
to four consecutive rows using a for loop, but I can't seem to figure it out.
I suspect that it can be done with the iter_rows module in the openpyxl
package, but I haven't been able to properly apply it within the loop. The
following piece of code results in the generation of an .xlsx file with the
last item from the tuple assigned to cell 'A2':

    
    
    from openpyxl import Workbook
    
    nfc_east = ('DAL', 'WAS', 'PHI', 'NYG')
    
    wb = Workbook()
    
    ws = wb.active
    
    row_cell = 2
    
    for i in nfc_east:
    
        column_cell = 'A'
        ws.cell(row = row_cell, column = column_cell).value = str(i)
        row_cell = row_cell + 1
    
    wb.save("row_creation_loop.xlsx")
    

All suggestions and (constructive) criticism welcome. Thank you!


Answer: Your code doesn't run for me (`Invalid column index A`). Which version of pyxl
are you using? AFAIK pyxl uses integer indexes. The following code produces
the output you're after (I think).

    
    
    from openpyxl import Workbook
    
    nfc_east = ('DAL', 'WAS', 'PHI', 'NYG')
    wb = Workbook()
    ws = wb.active
    
    start_row = 2
    start_column = 1
    
    for team in nfc_east:
        ws.cell(row=start_row, column=start_column).value = team
        start_row += 1
    
    wb.save("row_creation_loop.xlsx")
    
    #  Prints...
    #
    #   |  A  |
    # 1 |     |
    # 2 | DAL |
    # 3 | WAS |
    # 4 | PHI |
    # 5 | NYG |
    

