读取excel合并单元格内容
Posted linyihai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了读取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
以上是关于读取excel合并单元格内容的主要内容,如果未能解决你的问题,请参考以下文章