class UserInfo(object):
def __init__(self, excel_path=constants.EXCEL_PATH, sheet_name="Sheet1"):
self.data = xlrd.open_workbook(excel_path)
self.table = self.data.sheet_by_name(sheet_name)
self.keys = self.table.row_values(0)
self.row_num = self.table.nrows
self.col_num = self.table.ncols
def dict_data(self):
if self.row_num <= 1:
print("表内容行数为空")
else:
data = []
j = 1
for i in range(self.row_num - 1):
user_info = {}
values = self.table.row_values(j)
for x in range(self.col_num):
user_info[self.keys[x]] = values[x]
data.append(user_info)
j += 1
return data