From 73ce4d81189fe53647dad63a4530e424ecfd6f75 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sun, 11 Jul 2021 16:58:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=97=A0=E5=9B=BE=E9=9A=90?= =?UTF-8?q?=E6=82=A3=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- safesite/export.py | 41 ++++++++++++++++++--------------- safesite/templates/trouble.html | 9 ++++++++ safesite/views.py | 5 +++- 3 files changed, 36 insertions(+), 19 deletions(-) diff --git a/safesite/export.py b/safesite/export.py index ea6fe65e..9784f896 100644 --- a/safesite/export.py +++ b/safesite/export.py @@ -256,7 +256,7 @@ def exportdoc(a,id): import re 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': wb = load_workbook(dirname + 'safesite/exportemp/yhdc.xlsx') sheet = wb.active @@ -265,7 +265,11 @@ def exportxlsx(a,objs): row_height = 70 #查询数据 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.write('数量超过100,请查询后导出!') return res @@ -308,22 +312,23 @@ def exportxlsx(a,objs): sheet['r'+str(i+4)] = ILLEGAL_CHARACTERS_RE.sub(r'', v['zgms']) sheet['s'+str(i+4)] = v['shr__name'] sheet['t'+str(i+4)] = v['fcr__name'] - if v['yhtp']: - try: - img = Image(dirname + v['yhtp'][0]) - if img.format!='mpo': - img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高 - sheet.add_image(img, 'u'+str(i+4)) - except: - pass - if v['zghtp']: - try: - img = Image(dirname + v['zghtp'][0]) - if img.format!='mpo': - img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高 - sheet.add_image(img, 'w'+str(i+4)) - except: - pass + if pic==1: + if v['yhtp']: + try: + img = Image(dirname + v['yhtp'][0]) + if img.format!='mpo': + img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高 + sheet.add_image(img, 'u'+str(i+4)) + except: + pass + if v['zghtp']: + try: + img = Image(dirname + v['zghtp'][0]) + if img.format!='mpo': + img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高 + sheet.add_image(img, 'w'+str(i+4)) + except: + pass nowtime = datetime.now().strftime('%Y%m%d%H%M%S') sheet['b1'] = nowtime filename = 'YHS' + nowtime diff --git a/safesite/templates/trouble.html b/safesite/templates/trouble.html index e3f7d43e..11f7d8a3 100644 --- a/safesite/templates/trouble.html +++ b/safesite/templates/trouble.html @@ -31,6 +31,9 @@ {% if request|has_permission:'b_trouble_exportxls' %} 导出Excel {% endif %} + {% if request|has_permission:'b_trouble_exportxls' %} + 导出无图Excel + {% endif %}
@@ -329,6 +332,12 @@ window.open(url); // $('
').appendTo('body').submit().remove(); } + function exportyhexcel2() { + var querydata = $('#searchyhff').serializeJSON(); + let url = 'troublehandle?a=exportexcel&nopic=1&' + parseParams(querydata) + window.open(url); + // $('
').appendTo('body').submit().remove(); + } function delyh() { var row = $('#yhtable').datagrid('getSelected'); if (row) { diff --git a/safesite/views.py b/safesite/views.py index 789d654d..863a38cd 100644 --- a/safesite/views.py +++ b/safesite/views.py @@ -2057,7 +2057,10 @@ def troublehandle(req): a = a.filter(Q(zgbm__in=parts) | Q(fxbm__in=parts, zgbm=None)) if 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 elif a == 'del': userid = req.session['userid']