我有麻烦得到一列的所有行。我有这个
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)
但这是返回所有列的数量,不返回列的值,除了标题之外,如何获取列的所有值?
答案 0 :(得分:2)
您可以将所有单元格值存储在列表中,例如:
...
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 %}