How to detect merged cells in excel with openpyxl

前端 未结 4 2050
挽巷
挽巷 2020-12-31 08:37

I\'m trying to read data from excel sheet that contains merged cells. When reading merged cells with openpyxl the first merged cell contain the value and the rest of the cel

4条回答
  •  遥遥无期
    2020-12-31 09:21

    You can use merged_cells.ranges (merged_cell_ranges has been deprecated in version 2.5.0-b1 (2017-10-19), changed to merged_cells.ranges) on the sheet (can't seem to find per row) like this:

    from openpyxl import load_workbook
    wb = load_workbook(filename='a file name')
    sheet_ranges = wb['Sheet1']
    
    print(sheet_ranges.merged_cells.ranges)
    

提交回复
热议问题