| 查看: 2619 | 回复: 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 |
» 猜你喜欢
对氯苯硼酸纯化
已经有3人回复
求助:我三月中下旬出站,青基依托单位怎么办?
已经有12人回复
不自信的我
已经有12人回复
假如你的研究生提出不合理要求
已经有5人回复
所感
已经有4人回复
论文终于录用啦!满足毕业条件了
已经有28人回复
要不要辞职读博?
已经有7人回复
北核录用
已经有3人回复
实验室接单子
已经有3人回复
磺酰氟产物,毕不了业了!
已经有8人回复

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












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