|
@@ -1,3 +1,4 @@
|
|
|
+# -*- coding: UTF-8 -*-
|
|
|
import xlrd
|
|
|
import datetime
|
|
|
import uuid
|
|
@@ -12,7 +13,7 @@ def process_cell(table,i,j):
|
|
|
return str(int(_temp.value))
|
|
|
#raise "Error xls!"
|
|
|
|
|
|
-def processxls(FILE):
|
|
|
+def processPWXLS(FILE):
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
|
|
xlsname = os.path.join(BASE_DIR, 'uploads', '%s.xls' % str(uuid.uuid4()))
|
|
|
destination = open(xlsname,'wb')
|
|
@@ -23,35 +24,24 @@ def processxls(FILE):
|
|
|
table = data.sheet_by_index(0)
|
|
|
head = table.row_values(0)
|
|
|
assert len(head)==6
|
|
|
- assert head[0].strip()==u'\u5b66\u53f7'
|
|
|
- assert head[1].strip()==u'\u59d3\u540d'
|
|
|
- assert head[2].strip()==u'\u6027\u522b'
|
|
|
- assert head[3].strip()==u'\u5bc6\u7801'
|
|
|
- assert head[4].strip()==u'\u5206\u7ec4\u53f7'
|
|
|
- assert head[5].strip()==u'\u751f\u65e5'
|
|
|
+ assert head[0].strip()==u'作品ID'
|
|
|
+ assert head[1].strip()==u'参赛者用户名'
|
|
|
+ assert head[2].strip()==u'作品标题'
|
|
|
+ assert head[3].strip()==u'作品描述'
|
|
|
+ assert head[4].strip()==u'文件名'
|
|
|
+ assert head[5].strip()==u'文件扩展名'
|
|
|
|
|
|
|
|
|
|
|
|
rets=[]
|
|
|
for i in range(table.nrows-1):
|
|
|
col = table.row_values(i+1)
|
|
|
- sid=str(int(col[0]))
|
|
|
- name=process_cell(table,i+1,1)
|
|
|
- sex=col[2]
|
|
|
- password=process_cell(table,i+1,3)
|
|
|
- cid=str(int(col[4]))
|
|
|
-
|
|
|
- if table.cell(i+1,5).ctype==3:
|
|
|
- birthday = datetime.date(*xlrd.xldate_as_tuple(table.cell(i+1,5).value,data.datemode)[:3])
|
|
|
- else:
|
|
|
- try:
|
|
|
- birthday = datetime.datetime.strptime(process_cell(table,i+1,5), "%Y-%m-%d").date()
|
|
|
- except:
|
|
|
- try:
|
|
|
- birthday = datetime.datetime.strptime(process_cell(table,i+1,5), "%Y%m%d").date()
|
|
|
- except:
|
|
|
- pass
|
|
|
- #raise "Error xls!"
|
|
|
- rets.append((sid,name,sex,password,cid,birthday))
|
|
|
+ uuid = col[0]
|
|
|
+ user = col[1]
|
|
|
+ title = col[2]
|
|
|
+ desc = col[3]
|
|
|
+ filename = col[4]
|
|
|
+ fileext = col[5]
|
|
|
+ rets.append((uuid,user,title,desc,filename,fileext))
|
|
|
return rets
|
|
|
|