Python openpyxl 读取Excel
excel_path = os.getcwd() + '/resources/v6.xlsx'
ws = openpyxl.load_workbook(excel_path)
sheetnames = ws.sheetnames
读取第一个Sheet内容,从第2行开始读,读到100行:
sheet = ws[sheetnames[0]]
item_list = []
for row in range(2, 100):
item = dict()
name = sheet.cell(row, 1).value
if name is None or name == '':
break
item['name'] = name
item['code'] = sheet.cell(row, 2).value
item['sex'] = sheet.cell(row, 3).value
item['age'] = sheet.cell(row, 4).value
item['address'] = sheet.cell(row, 5).value
item['school'] = sheet.cell(row, 6).value
item_list.append(item)
return item_list