import xlrd def excel_to_list(file_path): # 导入须要读取的Excel表格的门路 workbook = xlrd.open_workbook(file_path) # workbook = xlrd.open_workbook(file_path) sheets_01 = workbook.sheet_by_name('sheet1') # sheets_01 = workbook.sheets()[0] # 创立一个空列表,存储Excel的数据 results = [] # 疏忽 excel 第一行的表头 list1 = [index for index in range(sheets_01.nrows) if index != 0] # 将excel表格内容导入到results列表中 HeaderList = HeaderLine.split(",") for rown in list1: _dic = {} for i in HeaderList: _dic[i] = sheets_01.cell_value(rown, HeaderList.index(i)) results.append(_dic) return results