pythonxlrd读取
发布时间: 2021-03-08 23:51:23
❶ python xlrd 读取值的问题。
#-*-coding:utf-8-*-
importwin32com.client
classeasyExcel:
def__init__(self,filename=None):
self.xlApp=win32com.client.Dispatch('Excel.Application')
iffilename:
self.filename=filename
self.xlBook=self.xlApp.Workbooks.Open(filename)
else:
self.xlBook=self.xlApp.Workbooks.Add()
self.filename=''
defsave(self,newfilename=None):
ifnewfilename:
self.filename=newfilename
self.xlBook.SaveAs(newfilename)
else:
self.xlBook.Save()
defclose(self):
self.xlBook.Close(SaveChanges=0)
delself.xlApp
defgetRange(self,sheet,row1,col1,row2,col2):
"returna2darray(i.e.tupleoftuples)"
sht=self.xlBook.Worksheets(sheet)
returnsht.Range(sht.Cells(row1,col1),sht.Cells(row2,col2)).Value
defsetRange(self,sheet,leftCol,topRow,data):
""".
"""
bottomRow=topRow+len(data)-1
rightCol=leftCol+len(data[0])-1
sht=self.xlBook.Worksheets(sheet)
sht.Range(
sht.Cells(topRow,leftCol),
sht.Cells(bottomRow,rightCol)
).Value=data
#举例,sheet1包含原始记录,现根据条件提取记录,写到sheet2.
if__name__=="__main__":
try:
xls=easyExcel(r'C:UsersNanDesktop est.xlsx')
arr=xls.getRange("Sheet1",2,1,7,3)
res=[]
forname,sex,scoreinarr:
ifname=='张三'andsex=='男':
res.append((name,sex,score))
#数组就包含你想要的数据了.下面这个只是为了证明.
xls.setRange("Sheet2",1,1,res)
finally:
xls.save()
xls.close()
用牛刀吧..方便快捷生动形象.
❷ Python 调用xlrd读取excel的时候报错
文件路径错了吧,
❸ python 简单 xls 读取 xlrd
defget_Excel_value_s1(col=0,File_Locaiton='C:Config.xlsx',User_Table='Configuration',):
result=[]
wb=xlrd.open_workbook(File_Locaiton)
sh=wb.sheet_by_name(User_Table)
forrowinrange(2,sh.nrows):
rowValuelist=sh.row_values(row)
get=rowValuelist[col]
result.append(get)
returnresult
forvalueinget_Excel_value_s1():
printvalue
为什么要每来次返回下一个源值,将所有值添加到列表,一次返回不行吗
❹ python中xlrd读入excel以后怎么调用
python有很多包可以操作excel单元 其中我用过的有xlrd ,xlwt 一个读一个写, 另外可用 openpyxl或者XlsxWriter 进行读写, 非常简单 读写单元格只需按列表一样读写元素即可 ws['A1'] = 42a = ws["A2"]对应的python模块用法可以参考网上教程!
❺ Python使用xlrd模块先读取Excel数据(如学生各科成绩表)并储存于字典中
importxlrd
data=xlrd.open_workbook('E:\成绩表.xls')
table=data.sheets()[0]
l=[]
foriinrange(table.nrows):
l.append(table.row_values(i))
这样sheet1的内容就都在名为l的list里了
❻ python操作excel,使用xlrd模块,获取某一列数据的语句为
a=[[table.cell(i,ord('A')-ord('A')).value,table.cell(i,ord('B')-ord('A')).value]foriinrange(1,nrows)]
❼ python xlrd怎么读取超链接
xls 可以 ,xlsx应该不行,要用openpyxl,xlrd 对xlsx的支持不太好
❽ python 如何读取 excel 指定单元格内容
1、首先打开电脑上编写python的软件。
❾ python xlrd如何获取Excel某行的全部值,附此代码
试试这样