使用openpyxl移动到相邻的单元格

我有一个algorithm,在单元格中find一个值,因为这种情况下,可以说这个单元格是C10。 我需要在D列的旁边看一个值,如果这个值不匹配我所需要的,从这个值上去一个单元格,并检查一个匹配等。我有这个到目前为止:

bits = [] for row in ws.iter_rows(row_offset=4,column_offset=3): #skip over empty rows if row: #current cell is in column C cell = row[2] try: #find the lowest address in the excel sheet if cell.internal_value == min(address): #somehow match up in column d for '''loop and search col D''': if str(row[3].internal_value).upper == ('CONTROL 1' or 'CON 1'): #add bits for cell in row[4:]: bits.append(cell.internal_value) #pass over cells that aren't a number, ie values that will never match an address except ValueError: pass except TypeError: pass 

有没有办法做到这一点? 我知道比较使用row[3]比较列D,但如果它不是正确的第一次,我不知道如何去列。 或者换句话说,改变row[value]的值row[value]周围移动,我需要知道什么值/如何在列中移动。

谢谢!

 bits = [] min_address = False for row in ws.iter_rows(row_offset=4,column_offset=3): c = row[2] d = row[3] if not d.internal_value: #d will always have a value if the row isn't blank if min_address: break #bits is what you want it to be now bits = [] #reset bits every time we hit a new row continue #this will just skip to next row for bits_cell in row[4:]: if bits_cell.internal_value: bits.append(bits_cell.internal_value) if c.internal_value: if c.internal_value == min(address): min_address = True #we set it to true, then kept going until blank row