From 19bb8a916e118748570fbb7883f095bd49b35de5 Mon Sep 17 00:00:00 2001 From: leijun Date: Fri, 4 Jan 2019 16:57:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=BB=9F=E8=AE=A1Excel?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=B8=BA=E5=90=8E=E5=8F=B0=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/nis/util/excel/ExcelCsv.java | 26 +++---- .../nis/web/controller/BaseController.java | 3 +- .../webapp/WEB-INF/include/form/pageGroup.jsp | 2 +- src/main/webapp/WEB-INF/views/index.jsp | 78 +++++++++++++++++-- src/main/webapp/WEB-INF/views/report/list.jsp | 11 ++- 5 files changed, 95 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/nis/util/excel/ExcelCsv.java b/src/main/java/com/nis/util/excel/ExcelCsv.java index 6d6e04cd6..6ddc09f38 100644 --- a/src/main/java/com/nis/util/excel/ExcelCsv.java +++ b/src/main/java/com/nis/util/excel/ExcelCsv.java @@ -264,15 +264,15 @@ public class ExcelCsv { * @param * @return list 数据列表 */ - public static Map> setDataList(Properties msgProp, Map dataMap, Map map){ - Map> dataList=new HashMap>(); + public static Map>> setDataList(Properties msgProp, Map dataMap, Map map){ + Map>> dataList=new HashMap>>(); Set keyList=dataMap.keySet(); for (String key : keyList) { List list=dataMap.get(key); - List listT=new ArrayList(); + List> listT=new ArrayList>(); for (E e : list){ int colunm = 0; - StringBuilder sb = new StringBuilder(); + List lisb=new ArrayList(); for (Object[] os : annotationMap.get(key)){ ExcelField ef = (ExcelField)os[0]; Object val = null; @@ -332,16 +332,17 @@ public class ExcelCsv { log.error("Get entity value failed",ex); val = ""; } - sb.append(val + "┆~"); + lisb.add(String.valueOf(val)); } - listT.add(String.valueOf(sb)); + listT.add(lisb); + //listT.add(String.valueOf(sb)); } dataList.put(key, listT); } return dataList; } - public static void writeCSVFile(HttpServletResponse response,List titleList,Map> headMap, Map> dataMap,String fileName, + public static void writeCSVFile(HttpServletResponse response,List titleList,Map> headMap, Map>> dataMap,String fileName, String titleTime,Properties msgProp) { try { // 写入临时文件 @@ -369,9 +370,9 @@ public class ExcelCsv { // 写入文件头部 writeHead(heads, cs); //获取文件内容 - List datas=dataMap.get(titleList.get(i)); + List> datas=dataMap.get(titleList.get(i)); // 写入文件内容 - for (String row : datas) { + for (List row: datas) { writeRow(row, cs); } } @@ -421,12 +422,11 @@ public class ExcelCsv { csvWriter.newLine(); } - private static void writeRow(String data, BufferedWriter csvWriter) throws Exception { + private static void writeRow(List data, BufferedWriter csvWriter) throws Exception { // 写入文件内容 //Html 解码 - data = Encodes.unescapeHtml(data.toString()); - String [] datas=data.split("┆~"); - for (String tag : datas) { + for (String tag : data) { + tag = Encodes.unescapeHtml(tag.toString()); StringBuffer sb = new StringBuffer(); if("null".equals(tag.trim())){ tag=null; diff --git a/src/main/java/com/nis/web/controller/BaseController.java b/src/main/java/com/nis/web/controller/BaseController.java index f850b9f5f..c63a10dcc 100644 --- a/src/main/java/com/nis/web/controller/BaseController.java +++ b/src/main/java/com/nis/web/controller/BaseController.java @@ -2273,8 +2273,7 @@ public class BaseController { } String titleTime=noExportMap.get("timeRange"); Map> headMap=ExcelCsv.ExcelCsvHeader(msgProp, titleList, noExportMap, classMap, 1); - Map> dataList=ExcelCsv.setDataList(msgProp, dataMap, map); - ByteArrayOutputStream out = new ByteArrayOutputStream(); + Map>> dataList=ExcelCsv.setDataList(msgProp, dataMap, map); ExcelCsv.writeCSVFile(response,titleList,headMap,dataList,fileName,titleTime,msgProp); } diff --git a/src/main/webapp/WEB-INF/include/form/pageGroup.jsp b/src/main/webapp/WEB-INF/include/form/pageGroup.jsp index da4255d80..cb6d3f916 100644 --- a/src/main/webapp/WEB-INF/include/form/pageGroup.jsp +++ b/src/main/webapp/WEB-INF/include/form/pageGroup.jsp @@ -71,7 +71,7 @@ function toPage(pageNo, pageSize, funcParam) { $('tbody').children().css('display', 'none'); //显示元素 $('tbody').children().slice((pageNo-1)*pageSize, pageNo*pageSize).css('display', ''); - totaltb(pageNo,pageSize); + showTotal(); } //底部跳页按钮 diff --git a/src/main/webapp/WEB-INF/views/index.jsp b/src/main/webapp/WEB-INF/views/index.jsp index 579ea84ec..d5cc42edf 100644 --- a/src/main/webapp/WEB-INF/views/index.jsp +++ b/src/main/webapp/WEB-INF/views/index.jsp @@ -249,6 +249,73 @@ append: null }); } + + + function getTitl(tableMark){ + var tb=document.getElementsByName(tableMark)[0]; + var rows = tb.rows; + var cells = tb.cells; + var colums = tb.rows[0].cells.length; + $("."+tableMark+" .count").empty(); + $("."+tableMark+" .count").append(""); + for(var j = 1; j < colums; j++){ + var sum = 0; + for(var i = 1;i"+sum+""); + } + } + + function getExport(tableId,url,titleName){ + loading(''); + getTitl(tableId); + var tb=document.getElementsByName(tableId); + var rows=tb[0].rows; + var list=new Array(); + list.splice(0,list.length); + var column=[]; //获取标题 + var index=[];//获取数据列下标 + var num=0; + $("table[name='"+tableId+"']").find("tr th").each(function(){ + if($(this).is(":visible")){ + column.push($(this).text().trim()); + index.push(num); + } + num++; + }); + for(var i=1 ; i 20){ + rowMap.push(rows[i].cells[n].title); + }else{ + rowMap.push(rows[i].cells[n].innerText); + } + }else{ + rowMap.push(rows[i].cells[n].innerText); + } + } + } + list[i-1]=rowMap; + } + var menuName = $("#menuName").val(); + var fileName = menuName + "_" + getNowFormatDate(); + var pztitle =$("#"+titleName).text(); + var map={}; + map.heard=column; + map.book=list; + map.titleTime=pztitle; + map.titleCode="config_service_statistics"; + var exports=JSON.stringify(map); + aJaxImportPost(url,{"exports":exports}); + $("."+tableId+" .count").empty(); + closeTip(); + } index @@ -260,9 +327,7 @@
- - [:${requestStatisticTime }] - + [:${requestStatisticTime }]
@@ -272,7 +337,7 @@
@@ -329,8 +394,7 @@
- - [:${configStatisticTime }] + [:${configStatisticTime }]
@@ -340,7 +404,7 @@
diff --git a/src/main/webapp/WEB-INF/views/report/list.jsp b/src/main/webapp/WEB-INF/views/report/list.jsp index ca8f70e5a..a5bc10067 100644 --- a/src/main/webapp/WEB-INF/views/report/list.jsp +++ b/src/main/webapp/WEB-INF/views/report/list.jsp @@ -101,7 +101,7 @@ $(document).ready(function() { var lipx=Number(li/6); lipx=lipx-3; $(".lireport").css({'width':lipx+'px','text-overflow':'ellipsis','overflow':'hidden'}); - + totaltb(1,-1); }); function getExportHead(){ // 报表导出 文件增加表头 @@ -372,6 +372,13 @@ function customColumnClick(){ $('#total').html(trtotal); } } + function showTotal(){ + if($("#total")!=null){ + $("#total").show(); + } + } + + window.onload=function (){ setTimeout(function (){ var height=document.documentElement.clientHeight; @@ -477,7 +484,7 @@ function customColumnClick(){ var column=[]; //获取标题 var index=[];//获取数据列下标 var num=0; - $("#"+tableId+" thead tr th").each(function(){ + $("#"+tableId).find("tr th").each(function(){ if($(this).is(":visible")){ column.push($(this).text().trim()); index.push(num);