读取excel合并单元格内容

 1  def get_excel_content(excel_path):
 2         contents = []
 3         if self.log_path.endswith('xls'):
 4             workbook = xlrd.open_workbook(excel_path, formatting_info=True)
 5             sheet = workbook.sheet_by_index(0)
 6             start_row = 0
 7             for cell in sheet.merged_cells:
 8                 row, row_range, col, col_range = cell
 9                 if row != start_row:
10                     # print()
11                     start_row = row
12                     at_1st_col = True
13                 else:
14                     at_1st_col = False
15                 if at_1st_col or start_row == 0:
16                     content = [item for item in sheet.row_values(row) if (item and item != '/' or item == 0)]
17                     if content:
18                         # print(content, end="        ")
19                         contents.append(content)
20         return contents
原文地址:https://www.cnblogs.com/linyihai/p/10140958.html