Skip to content Skip to sidebar Skip to footer

Openpyxl: Concatenation Of Several Columns Into One Cell Per Row (multi-row)

This question is a follow up to: Openpyxl: TypeError - Concatenation of several columns into one cell per row What I want to do: I want to concatenate the cells from columns F to M

Solution 1:

Correct implementation:

def concat_f_to_m():
for row_value in range(1, sheet.max_row+1):
    values=[]
    del values[:]
    for row in sheet.iter_rows(min_col=6, max_col=14, min_row=row_value, max_row=row_value):
        for cell in row:
            if cell.value != None:

                values.append(str(cell.value))
                sheet[f'E{row_value}'].value= ''.join(values)
            else:
                del values[:] 
                break

concat_f_to_m()

Post a Comment for "Openpyxl: Concatenation Of Several Columns Into One Cell Per Row (multi-row)"