共计 486 个字符,预计需要花费 2 分钟才能阅读完成。
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
正文完