|
@@ -1,7 +1,8 @@
|
|
|
-import xlrd
|
|
|
+import xlrd,xlwt
|
|
|
import datetime
|
|
|
import uuid
|
|
|
import os
|
|
|
+from django.conf import settings
|
|
|
|
|
|
|
|
|
def process_cell(table,i,j):
|
|
@@ -12,8 +13,13 @@ def process_cell(table,i,j):
|
|
|
return str(int(_temp.value))
|
|
|
#raise "Error xls!"
|
|
|
|
|
|
-def processxls(FILE):
|
|
|
+def randompass():
|
|
|
+ return uuid.uuid4().get_bytes().encode("base64")[:10]
|
|
|
+
|
|
|
+def GeneratePasswdToXls(FILE):
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
|
|
|
+ wrxlsname = 'pwdout-%s.xls' % str(uuid.uuid4())
|
|
|
+ wrxlspath = os.path.join(settings.MEDIA_ROOT,'xls',wrxlsname )
|
|
|
xlsname = os.path.join(BASE_DIR, 'uploads', '%s.xls' % str(uuid.uuid4()))
|
|
|
destination = open(xlsname,'wb')
|
|
|
for chunk in FILE.chunks():
|
|
@@ -31,14 +37,20 @@ def processxls(FILE):
|
|
|
assert head[5].strip()==u'\u751f\u65e5'
|
|
|
|
|
|
|
|
|
-
|
|
|
- rets=[]
|
|
|
+ rwb = xlwt.Workbook(encoding='utf-8')
|
|
|
+ rsh = rwb.add_sheet('Sheet1')
|
|
|
+ rsh.write(0,0,u'\u5b66\u53f7')
|
|
|
+ rsh.write(0,1,u'\u59d3\u540d')
|
|
|
+ rsh.write(0,2,u'\u6027\u522b')
|
|
|
+ rsh.write(0,3,u'\u5bc6\u7801')
|
|
|
+ rsh.write(0,4,u'\u5206\u7ec4\u53f7')
|
|
|
+ rsh.write(0,5,u'\u751f\u65e5')
|
|
|
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)
|
|
|
+ password=randompass()
|
|
|
cid=str(int(col[4]))
|
|
|
|
|
|
if table.cell(i+1,5).ctype==3:
|
|
@@ -51,7 +63,14 @@ def processxls(FILE):
|
|
|
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))
|
|
|
- return rets
|
|
|
+
|
|
|
+ rsh.write(i+1,0,sid)
|
|
|
+ rsh.write(i+1,0,name)
|
|
|
+ rsh.write(i+1,0,sex)
|
|
|
+ rsh.write(i+1,0,password)
|
|
|
+ rsh.write(i+1,0,cid)
|
|
|
+ rsh.write(i+1,0,birthday)
|
|
|
+ rwb.save(wrxlspath)
|
|
|
+ return wrxlsname
|
|
|
+
|
|
|
|