我正在上传一个excel表格(.xls或.xlsx格式)。上传文件后,我想读取每列的值。
我的html是
<form id = "ListForm" name = "ListForm" action = "" method = 'POST' enctype="multipart/form-data">
<table>
<tr>
<td>PM List</td>
<td><input type="file" name="file_pm" id="file_pm" ></td>
</tr>
<tr><td><input type="submit" value="Upload" name="pmUpload" id="pmUpload" class="button"></td></tr>
</table>
</form>
Python代码
def pmUpload(request):
data = request.FILES['file_pm']
# here I want to iterate through each column & rows in excel.
谁能告诉我迭代的方法
您可以使用csv
python库。
file = open('file.xls')
csvreader = csv.reader(file, delimiter=',')
for r in csvreader: # iterates each row
print r # r is a list of column of that row.
希望能有所帮助。