使用 xlrd 迭代所有列 [英] Iterating all columns with xlrd
本文介绍了使用 xlrd 迭代所有列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法获取一列的所有行.我有这个
Im having troubles getting all the row of a column. i have this
def excel(request):
file_location = "proyectos.xls"
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(0)
for col in range(sheet.ncols):
data = sheet.cell_value(0,col)
return HttpResponse (data)
但这是返回所有列的数量,不返回列的值,如何获取除标题之外的列的所有值?
but this is returning the number of the all columns, does not return the values of the columns, how can i get all the values of a column excepting the header?
推荐答案
您可以将所有单元格值存储在一个列表中,例如:
You could store all the cell values in a list, e.g.:
...
row = []
for col in range(sheet.ncols):
row.append( sheet.cell_value(0,col) )
return render_to_response('your_template.html', {'row': row})
在您的模板中,例如:
{% for i in row %}
<p>{{ i }}</p>
{% endfor %}
这篇关于使用 xlrd 迭代所有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文