26 lines
882 B
Python
26 lines
882 B
Python
from openpyxl.workbook import Workbook
|
|
from django.conf import settings
|
|
from datetime import datetime
|
|
from openpyxl.styles import Font, Fill
|
|
|
|
|
|
BASE_DIR = settings.BASE_DIR
|
|
|
|
def export_test(tests):
|
|
'''
|
|
params: serializer tests
|
|
return: xlsx path
|
|
'''
|
|
wb = Workbook()
|
|
ws1 = wb.active
|
|
ws1.title = '用户表'
|
|
ws1.append(['类型','用户姓名', '用户单位', '工作类别', '押题卷', '得分', '耗时', '答题时间'])
|
|
row = ws1.row_dimensions[1]
|
|
row.font = Font(bold=True)
|
|
for i in tests:
|
|
ws1.append([i['type'], i['consumer_name'], i['consumer_company_name'], i['workscope_name'], i['paper_name'], i['score'], i['took_format'], i['start_time']])
|
|
filename = 'tests' + datetime.now().strftime("%Y%m%d%H%M%S") +'.xlsx'
|
|
path = '/media/export/' + filename
|
|
wb.save((BASE_DIR + path).replace('\\', '/'))
|
|
return path
|