Openpyxl: Concatenation of several columns into one cell per row (Multi-row)

前端 未结 1 1424
慢半拍i
慢半拍i 2021-01-26 04:06

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 t

相关标签:
1条回答
  • 2021-01-26 04:46

    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()
    
    0 讨论(0)
提交回复
热议问题