37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
# -*- coding:utf-8 -*-
|
||
import xlrd
|
||
import json
|
||
|
||
usersFile="Users.xlsx"
|
||
|
||
wb=xlrd.open_workbook(filename=usersFile)
|
||
sheet=wb.sheet_by_index(0)
|
||
rows=sheet.nrows
|
||
if rows==0:
|
||
print("excel文件错误,请检查")
|
||
exit()
|
||
print("共有{}行用户信息".format(rows))
|
||
i=0
|
||
rList=[]
|
||
while i<rows:
|
||
print("获取用户名{}密码{}".format(sheet.cell(i,0).value,sheet.cell(i,1).value))
|
||
user={}
|
||
user['userName']=sheet.row(i)[0].value.strip()
|
||
user['userPwd']=sheet.row(i)[1].value.strip()
|
||
if len(sheet.row(i))>2:
|
||
user['idCustomer']=sheet.row(i)[2].value.strip()
|
||
else:
|
||
user['idCustomer']=""
|
||
rList.append(user)
|
||
if (i+1)%7==0:
|
||
print("生成最终用户信息文件config/users{}.json".format(i+1))
|
||
with open('config/users{}.json'.format(i+1),'w') as f:
|
||
json.dump(rList,f)
|
||
rList=[]
|
||
i+=1
|
||
#刚好是奇数位结尾
|
||
if len(rList)>0:
|
||
print("生成最终用户信息文件config/users{}.json".format(i+1))
|
||
with open('config/users{}.json'.format(i+1),'w') as f:
|
||
json.dump(rList,f)
|