excel - Python - How to use a for loop to write data to a cell, then move to the next row -
i have feels problem relatively simple solution, point escapes research. i'm attempting write items tuple 4 consecutive rows using loop, can't seem figure out. suspect can done iter_rows module in openpyxl package, haven't been able apply within loop. following piece of code results in generation of .xlsx file last item tuple assigned cell 'a2':
from openpyxl import workbook nfc_east = ('dal', 'was', 'phi', 'nyg') wb = workbook() ws = wb.active row_cell = 2 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 , (constructive) criticism welcome. thank you!
if want write cells tuple, can directly syntax - ws['a1'] = <something>
write value cell a1
.
example -
from openpyxl import workbook nfc_east = ('dal', 'was', 'phi', 'nyg') wb = workbook() ws = wb.active row, in enumerate(nfc_east): column_cell = 'a' ws[column_cell+str(row+2)] = str(i) wb.save("row_creation_loop.xlsx")
when using syntax - ws.cell(row = row_cell, column = column_cell).value
, column_cell has integer, not string , a
column, have give value column
argument 1
(for b
2
) , etc.
Comments
Post a Comment