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()

运行结果如下
在这里插入图片描述

posted @ 2020-10-19 09:34  skyxq  阅读(92)  评论(0)    收藏  举报