导出无图隐患列表

This commit is contained in:
caoqianming 2021-07-11 16:58:26 +08:00
parent b9a3b9cf58
commit 73ce4d8118
3 changed files with 36 additions and 19 deletions

View File

@ -256,7 +256,7 @@ def exportdoc(a,id):
import re import re
ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]') ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]')
def exportxlsx(a,objs): def exportxlsx(a,objs,pic=1):
if a =='yh': if a =='yh':
wb = load_workbook(dirname + 'safesite/exportemp/yhdc.xlsx') wb = load_workbook(dirname + 'safesite/exportemp/yhdc.xlsx')
sheet = wb.active sheet = wb.active
@ -265,7 +265,11 @@ def exportxlsx(a,objs):
row_height = 70 row_height = 70
#查询数据 #查询数据
yhobjs = objs.order_by('-troubleid') yhobjs = objs.order_by('-troubleid')
if yhobjs.count()>100: if yhobjs.count()>1000:
res = HttpResponse()
res.write('数量超过1000,请查询后导出!')
return res
if pic==1 and yhobjs.count()>100:
res = HttpResponse() res = HttpResponse()
res.write('数量超过100,请查询后导出!') res.write('数量超过100,请查询后导出!')
return res return res
@ -308,22 +312,23 @@ def exportxlsx(a,objs):
sheet['r'+str(i+4)] = ILLEGAL_CHARACTERS_RE.sub(r'', v['zgms']) sheet['r'+str(i+4)] = ILLEGAL_CHARACTERS_RE.sub(r'', v['zgms'])
sheet['s'+str(i+4)] = v['shr__name'] sheet['s'+str(i+4)] = v['shr__name']
sheet['t'+str(i+4)] = v['fcr__name'] sheet['t'+str(i+4)] = v['fcr__name']
if v['yhtp']: if pic==1:
try: if v['yhtp']:
img = Image(dirname + v['yhtp'][0]) try:
if img.format!='mpo': img = Image(dirname + v['yhtp'][0])
img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高 if img.format!='mpo':
sheet.add_image(img, 'u'+str(i+4)) img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高
except: sheet.add_image(img, 'u'+str(i+4))
pass except:
if v['zghtp']: pass
try: if v['zghtp']:
img = Image(dirname + v['zghtp'][0]) try:
if img.format!='mpo': img = Image(dirname + v['zghtp'][0])
img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高 if img.format!='mpo':
sheet.add_image(img, 'w'+str(i+4)) img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高
except: sheet.add_image(img, 'w'+str(i+4))
pass except:
pass
nowtime = datetime.now().strftime('%Y%m%d%H%M%S') nowtime = datetime.now().strftime('%Y%m%d%H%M%S')
sheet['b1'] = nowtime sheet['b1'] = nowtime
filename = 'YHS' + nowtime filename = 'YHS' + nowtime

View File

@ -31,6 +31,9 @@
{% if request|has_permission:'b_trouble_exportxls' %} {% if request|has_permission:'b_trouble_exportxls' %}
<a id="exportexcel" onclick="exportyhexcel()">导出Excel</a> <a id="exportexcel" onclick="exportyhexcel()">导出Excel</a>
{% endif %} {% endif %}
{% if request|has_permission:'b_trouble_exportxls' %}
<a id="exportexcel" onclick="exportyhexcel2()" class='easyui-linkbutton' data-options="iconCls: 'fa-download',plain:true">导出无图Excel</a>
{% endif %}
</div> </div>
<div id="sdg_yh" class="easyui-dialog" title="筛选条件" style="width:400px;height:420px;" <div id="sdg_yh" class="easyui-dialog" title="筛选条件" style="width:400px;height:420px;"
data-options="iconCls:'fa-search',resizable:true,modal:true,closed:true,border:false"> data-options="iconCls:'fa-search',resizable:true,modal:true,closed:true,border:false">
@ -329,6 +332,12 @@
window.open(url); window.open(url);
// $('<form method="post" action="' + url + '"></form>').appendTo('body').submit().remove(); // $('<form method="post" action="' + url + '"></form>').appendTo('body').submit().remove();
} }
function exportyhexcel2() {
var querydata = $('#searchyhff').serializeJSON();
let url = 'troublehandle?a=exportexcel&nopic=1&' + parseParams(querydata)
window.open(url);
// $('<form method="post" action="' + url + '"></form>').appendTo('body').submit().remove();
}
function delyh() { function delyh() {
var row = $('#yhtable').datagrid('getSelected'); var row = $('#yhtable').datagrid('getSelected');
if (row) { if (row) {

View File

@ -2057,7 +2057,10 @@ def troublehandle(req):
a = a.filter(Q(zgbm__in=parts) | Q(fxbm__in=parts, zgbm=None)) a = a.filter(Q(zgbm__in=parts) | Q(fxbm__in=parts, zgbm=None))
if fxrname: if fxrname:
a = a.filter(fxr__name=fxrname) a = a.filter(fxr__name=fxrname)
res = exportxlsx('yh', a) if req.GET.get('nopic', None):
res = exportxlsx('yh', a, 0)
else:
res = exportxlsx('yh', a)
return res return res
elif a == 'del': elif a == 'del':
userid = req.session['userid'] userid = req.session['userid']