标签:python
import xlrd
LstDictInfo =[{‘id‘:1,‘name‘:‘student1‘,‘age‘:10},
{‘id‘:2,‘name‘:‘student2‘,‘age‘:11},
{‘id‘:3,‘name‘:‘student3‘,‘age‘:12}]
class Dict2xlrd():
def __int__(self,LstDictInfo):
self.LstDictInfo = LstDictInfo
#def dict2csv(self,lstDictInfo,strFilePath,lstFieldNames):
def xlrd2dict(self,strFilePath):
#读取excel文件
data = xlrd.open_workbook(strFilePath)
#获取一个工作表
sheet1 = data.sheets()[0]
#获取工作表的行数
rows =sheet1.nrow
#获取工作表的列数
cols = sheet1.ncols
#读取每一行的数据
row_list = []
for i in range(2,nrows):
row_data = ssheet1h.row_values(i)
row_list.append(row_data)
data = xlrd.open_workbook(‘data.xlsx‘)
#获取一个工作表
sheet1 = data.sheets()[0]
#获取工作表的行数
rows =sheet1.nrows
#获取工作表的列数
cols = sheet1.ncols
#读取每一行的数据
row_list = []
edict=[]
for i in range(1,rows):
row_data = sheet1.row_values(i)
row_list.append(row_data)
edict[1]=dict(username=‘row_list[1][0]‘,password=‘row_list[1][1]‘)
标签:python
原文地址:http://9603083.blog.51cto.com/9593083/1871565