复制到代码即可运行
import openpyxl
def read_excel_file(self):
is_have_title = True
path = "商品信息.xlsx"
sheet = "message"
information = ['code', 'name', 'specifications', 'company', 'setPrice']
all_drugs_dict = []
try:
workbook = openpyxl.load_workbook(path)
sheet = workbook[sheet]
for index, row in enumerate(sheet.rows):
drugs_dict = {}
if index == 0 and is_have_title: continue
for row_index, row_value, in enumerate(row):
drugs_dict[information[row_index]] = row_value.value
all_drugs_dict.append(drugs_dict)
except Exception as e:
raise e
return all_drugs_dict
|