Python用xlrd读取excel文件

import xlrd
def read_excel():
wb=xlrd.open_workbook(r’D:\pycharm\APP\3.xlsx’)#打开工作簿
# ws=wb.sheet_names()#用工作簿获取所有工作表sheet
# print(ws)
ws=wb.sheet_by_index(1)#通过索引拿到工作表sheet
list1=[]
for i in range(1,ws.nrows):#行和列的索引
dic = {}
dic[‘姓名’]=ws.cell_value(i,0)
dic[‘年龄’]=ws.cell_value(i,1)
dic[‘性别’]=ws.cell_value(i,2)
dic[‘职业’]=ws.cell_value(i,3)
list1.append(dic)#把每次遍历行列得到的字典加入列表
for j in list1:#遍历列表拿到字典
print(j)
read_excel()

Python用xlrd读取excel文件
Python用xlrd读取excel文件

相关文章: