I am working on an openpyxl script and am hitting a roadblock on referencing a row number through an iteration of 'for row in sheet.iter_rows'. When attempting to call it without values_only=True it will pull the tuple of the true coordinates of the populated cells. If I call it with values_only=True, it pulls the values of each populated cell.
I'm attempting to fill in column G of whichever row the iteration is on with a formula based on two cells on the same row. I've found a way to get the row number if I am doing it based directly on cell coordinate, but iterating through all of the cells would be inefficient. 4 row iteration > 30 cell iteration.
--Not a duplicate of accessing the index in 'for' loops. That would be calling a specific section of the list generated by p1.iter_rows(min_row=2, values_only=True, I'm trying to reference the row # designation that the for loops is currently on. E.G. If it is on row 2, it would place a 2 after 'D', 'C', or 'G' in the code above. Enumerate would be doing the same thing. I don't need access to the list itself, I need the categorical reference number of the row that is currently being iterated
for row in p1.iter_rows(min_row=2, values_only=True):
cvalue = p1['D' + str(row)]
msrp = p1['C' + str(row)]
p1['G' + str(row)] = msrp * int(.0825) + cvalue
test = p1.row.coordinate
Corrected code:
for row in p1.iter_rows(min_row=2, min_col=3, max_col=3):
for cell in row:
xy = coordinate_from_string(cell.coordinate)
colcoor = column_index_from_string(xy[0])
rowcoor = xy[1]
cval = p1['C' + str(rowcoor)]
pval = p1['D' + str(rowcoor)]