How to get value present in a merged cell?

后端 未结 5 394
星月不相逢
星月不相逢 2021-01-12 19:58

I want to get value of a merged cell that has range from D3 to H3 using openpyxl library. As per my understanding most libraries read data from 1st cell itself. Thus the mer

5条回答
  •  孤街浪徒
    2021-01-12 20:52

    from openpyxl import * 
    from openpyxl.utils import *
    
        def getValueWithMergeLookup(sheet, cell):
            if cell == None or sheet == None:
                return None
            for irange in sheet.merged_cell_ranges:
                min_col, min_row, max_col, max_row =range_boundaries(irange)
                if cell.row in range(min_row,max_row+1) and column_index_from_string(cell.column) in range(min_col,max_col+1):
                    return sheet.cell(None,min_row,min_col).value
            return cell.value
    

提交回复
热议问题