Using xlrd to get list of excel values in python

孤者浪人 提交于 2019-12-06 21:14:06
for i in range(worksheet.nrows):

will iterate through all the rows in the worksheet

if you were interested in column 0 for example

c0 = [worksheet.row_values(i)[0] for i in range(worksheet.nrows) if worksheet.row_values(i)[0]]

or even better make this a generator

column_generator = (worksheet.row_values(i)[0] for i in range(worksheet.nrows))

then you can use itertools.takewhile for lazy evaluations... that will stop when you get your first empty... this will provide better performance if you just want to stop once you get your first empty value

from itertools import takewhile
print list(takewhile(str.strip,column_generator))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!