合并单元格
操作方法:
1.使用xlrd自带属性:merged_cells
# 获取表格中所有合并单元格位置,以列表形式返回 (起始行,结束行,起始列,结束列)
merged = sheet.merged_cells #结果:[(1,5,0,1),(5,9,0,1)]
2.使用循环判断是合并单元格还是普通单元格,并将合并单元格中的首行值赋值给合并单元格
def get_cell_type(row_index, col_index):
"""既能得到合并单元格也能得到普通单元格"""
cell_value = None
for (rlow, rhigh, clow, chigh) in merged: # 遍历表格中所有合并单元格位置信息
# print(rlow,rhigh,clow,chigh)
if (row_index >= rlow and row_index < rhigh): # 行坐标判断
if (col_index >= clow and col_index < chigh): # 列坐标判断
# 如果满足条件,就把合并单元格第一个位置的值赋给其它合并单元格
cell_value = sheet.cell_value(rlow, clow)
print('合并单元格')
break