data = xlrd.open_workbook(r"./demo.xlsx")
# 获取sheet
table = data.sheet_by_name('Vehicle RTM')
The combined function of the following cell of the start and end columns lie_detection colspan into the dictionary.
def cell_detection(lie_detection):
# 计算出合并的单元格有哪些
colspan = {}
if table.merged_cells:
for item in table.merged_cells:
for row1 in range(item[0], item[1]):
for col1 in range(item[2], item[3]):
if col1 == lie_detection:
if row1 > 3:
# 合并单元格的首格是有值的,所以在这里进行了去重
if (row1, col1) != (item[0], item[2]):
colspan.update({(row1, col1): (item[0], item[2])})
return colspan
How to determine the combined line and the maximum value of the row See Part blog usage dictionary.