读取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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM