How to get value present in a merged cell?

后端 未结 5 393
星月不相逢
星月不相逢 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:42

    I wrote this based on the latest source code from Openpyxl:

    def getMergedCellVal(sheet, cell):
        rng = [s for s in sheet.merged_cells.ranges if cell.coordinate in s]
        return sheet.cell(rng[0].min_row, rng[0].min_col).value if len(rng)!=0 else cell.value
    

提交回复
热议问题