| 查看: 2700 | 回复: 0 | |||
[交流]
python利用xlrd完成excel中某列检索含有指定字符串的记录(原代)
|
|
import os import xlrd,sys # input the excel file Filename=raw_input('input the file name&path:') if not os.path.isfile(Filename): raise NameError,"%s is not a valid filename"%Filename #open the excel file bk=xlrd.open_workbook(Filename) #get the sheets number shxrange=range(bk.nsheets) print shxrange #get the sheets name for x in shxrange: p=bk.sheets()[x].name.encode('utf-8') print "Sheets Number(%s): %s" %(x,p.decode('utf-8')) # input your sheets name sname=int(raw_input('choose the sheet number:')) try: sh=bk.sheets()[sname] except: print "no this sheet" #return None nrows=sh.nrows ncols=sh.ncols # return the lines and col number print "line:%d col:%d" %(nrows,ncols) #input the check column columnnum=int(raw_input('which column you want to check pls input the num(the first colnumn num is 0):')) while columnnum+1>ncols: columnnum=int(raw_input('your num is out of range,pls input again:')) # input the searching string and column testin=raw_input('input the string:') #find the cols and save to a txt outputfilename=testin + '.txt' outputfile=open(outputfilename,'w') #find the rows which you want to select and write to a txt file for i in range(nrows): cell_value=sh.cell_value(i, columnnum) if testin in str(cell_value): outputs=sh.row_values(i) for tim in outputs: outputfile.write('%s ' %(tim)) outputfile.write('%s' %(os.linesep)) outputfile.close() 我的空间:http://user.qzone.qq.com/384327409/blog/1326700667 |
» 猜你喜欢
售SCI一区T0P文章,我:8O.55.1.O.5.4,科目齐全,可+急
已经有5人回复
售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急
已经有7人回复
上海工程技术大学 激光智能制造课题组 2027级博士研究生招生
已经有6人回复
课题组招2027级博士 上海工程技术大学 激光智能制造方向
已经有6人回复
现代”学阀”该如何界定
已经有14人回复
求合成方法
已经有8人回复
师弟论文见刊大半年才想起来申请专利,还能抢救一下吗?
已经有4人回复
有机合成以后会不会被AI改变?做科研的虫友怎么看
已经有8人回复
我的奶奶
已经有3人回复

找到一些相关的精华帖子,希望有用哦~
帮忙查询一篇文章是否被EI或ISTP检索
已经有3人回复
怎样判断二氧化钛粉末的悬浮液中是否含有氧化锌和醋酸锌?
已经有17人回复
那些免费开放的电子图书馆
已经有20人回复
利用电化学方法制备石墨烯/四氧化三钴
已经有3人回复
求助:怎样在sciencefinder里检索一个化合物的衍生物有哪些?万分感谢
已经有4人回复
[求助]哪位好人学校可以使用微谱数据库,帮我检索几个化合物的母核。谢谢!
已经有4人回复
lammps求助:计算含有不同原子体系的热导率的in文件该怎么修改
已经有7人回复
论文可以在网上看到了,多久会检索
已经有7人回复
求蛋白纯化方面的文献资料检索!!
已经有11人回复
求助文章"ESI高被引论文”和“他引次数"。
已经有5人回复
怎么才能知道能不能做一种药品呢(在中国)
已经有3人回复
科研从小木虫开始,人人为我,我为人人










回复此楼
点击这里搜索更多相关资源