pyhton获取excel测试数据
import xlrd
def get_excle():
#打开需要获取excel数据
file_excle=xlrd.open_workbook(r’D:\phone.xlsx’)
#读取excel中第一个sheet数据(也可以用sheet_by_name(sheet名称))
data=file_excle.sheets()[0]
#定义一个字典存放从excle获取的数据
table = []
#循环从excle中取数
for rown in range(data.nrows-1):
arry={‘phone’:’’,‘pwd’:’’}
#将excle中rown+1行,2列的数据赋给如下变量
arry[‘phone’]=data.cell_value(rown+1,2)
arry[‘pwd’]=data.cell_value(rown+1,3)
#将取excle值放到上面定义的自定中
table.append(arry)
for i in table:
print(i)
get_excle()
运行结果如下