1. 需要的js

/*** 弹出下载Excel窗口**/
functionpopResetVoucherCode(param) {var url = "***Controller.do?**functionOne";url+= ("&param=" +param);$.dialog.setting.zIndex= getzIndex(true);if (typeof(windowapi) == 'undefined') {$.dialog({content:"url:" +url,zIndex: getzIndex(),lock:true,title: $.i18n.prop('dialog.reset.voucher.code.select'),width:700,height:300,ok:function() {iframe= this.iframe.contentWindow;var saveUrl = "***Controller.do?**functionTwo";$("#formobj",iframe.document).attr('action',saveUrl);    //通过jquery为action属性赋值
saveObj();return false;},okVal:'下载',cache:false,cancelVal: $.i18n.prop('dialog.close'),cancel:true /*为true等价于function(){}*/});}else{$.dialog({//使用W,即为使用顶级页面作为openner,造成打开的次级窗口获取不到关联的主窗口content: 'url:' +url,lock:true,width: width,zIndex: getzIndex(),height: height,parent: windowapi,title: title,opacity:0.3,ok:function() {iframe= this.iframe.contentWindow;var saveUrl = "***Controller.do?**function";$("#formobj",iframe.document).attr('action',saveUrl);    //通过jquery为action属性赋值
saveObj();return false;},okVal:'下载',cache:false,cancelVal: $.i18n.prop('dialog.close'),cancel:true /*为true等价于function(){}*/});}
}/*** Jeecg Excel 导出* 代入查询条件*  url:        后台处理地址*   atagridId   需要刷新的datagrid的标识位*/
functionJeecgExcelExport(url,datagridId){var queryParams = $('#'+datagridId).datagrid('options').queryParams;$('#'+datagridId+'tb').find('*').each(function() {queryParams[$(this).attr('name')] = $(this).val();});var params = '&';$.each(queryParams,function(key, val){params+='&'+key+'='+val;});var fields = '&field=';$.each($('#'+ datagridId).datagrid('options').columns[0], function(i, val){if(val.field != 'opt'){fields+=val.field+',';}});var id='&id=';$.each($('#'+ datagridId).datagrid('getSelections'), function(i, val){id+=val.id+",";});window.location.href= url+ encodeURI(fields+params+id);
}//表单提交,触发
$(document).ready(function() {//表单提交$("#formobj").Validform({btnSubmit :"#btn_sub",btnReset :"#btn_reset"});
});

  

2.jsp 操作下载Excel 的窗口

<%@ page language="java"import="java.util.*"contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" %>
<%@include file="/context/mytags.jsp" %>
<!DOCTYPE html>
<html>
<head><title>下载Excel</title><linkhref="${webRoot}/plug-in/tools/css/metrole/common.css"rel="stylesheet"type="text/css"><t:basetype="jquery,easyui,tools,DatePicker,validform"></t:base><scriptsrc="${webRoot}/plug-in/lhgDialog/lhgdialog.min.js"></script><scriptsrc="${webRoot}/plug-in/jquery-plugs/i18n/jquery.i18n.properties.js"></script><scriptsrc="${webRoot}/plug-in/tools/curdtools.js"></script><scriptsrc="${webRoot}/plug-in/easyui/extends/datagrid-groupview.js"></script><linkhref="${webRoot}/plug-in/tools/css/metrole/common.css"rel="stylesheet"type="text/css"><linkrel="stylesheet"href="${webRoot}/plug-in/bootstrap-select-1.13.2/dist/css/bootstrap-select.min.css"><scriptsrc="${webRoot}/plug-in/bootstrap-select-1.13.2/js/bootstrap-select.js"></script><%@ include file="/webpage/common/select2.jsp" %><scripttype="text/javascript">$(function() {});</script>
</head>
<bodystyle="overflow-y: hidden"scroll="no">
<t:formvalidformid="formobj"refresh="true"dialog="true"action="***Controller.do?**functionTwo"layout="table"><br><tablecellpadding="0"cellspacing="1"class="formtable"><tbody><tr><tdalign="right"style="width: 25%"><labelclass="Validform_label">主体:</label></td><tdclass="value"style="width: 75%"><inputtype="text"style="width: 90%"class="text conditionValue"value="${**Name}"><inputname="id"type="hidden"value="${**Id}"></td></tr><tr><tdalign="right"><labelclass="Validform_label">条件:</label></td><tdclass="value"><selectname="entityName"id="entityName"style="width: 90%;margin-right: 20px;padding-top: 0px;"class="input-sm useWith"><c:forEachitems="${**Map}"var="entry"varStatus="vs"><optionvalue="${entry.key}" > ${entry.value}</option></c:forEach></select></td></tr></tbody></table>
</t:formvalid>
</body>
</html>

3.1 后台处理方式一:

@RequestMapping(params = "voucherDownBill")public String**FunctionTwo(HttpServletRequest request, HttpServletResponse response, ModelMap map) {AjaxJson resultJson= newAjaxJson();Class clazz= null;List list= newArrayList();list.add(entity);String fileName= "导出文件标题";try{ExportParams params= new ExportParams(fileName + "列表", fileName, ExcelType.HSSF);Workbook workbook=ExcelExportUtil.exportExcel(params, clazz, list);SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(fileName + "列表" + dateFormat.format(new Date()) + "" + ".xls", "UTF-8"));//组装附件名称和格式ServletOutputStream out =response.getOutputStream();workbook.write(out);out.flush();out.close();}catch(IOException e){e.printStackTrace();logger.error("导出失败");}returnNormalExcelConstants.JEECG_EXCEL_VIEW;}

3.2 后台处理方式二:

@RequestMapping(params = "voucherDownBill")public String**FunctionTwo(HttpServletRequest request, HttpServletResponse response, ModelMap map) {AjaxJson resultJson= newAjaxJson();Class clazz= null;List list= newArrayList();Entity entity= newEntity();entity.set(***);clazz=entity.getClass();list.add(entity);String fileName= "导出文件标题";map.put(NormalExcelConstants.FILE_NAME, fileName);map.put(NormalExcelConstants.CLASS, clazz);map.put(NormalExcelConstants.PARAMS,new ExportParams(fileName + "列表", "导出人:"+ ResourceUtil.getSessionUser().getRealName(), "导出信息"));map.put(NormalExcelConstants.DATA_LIST, list);returnNormalExcelConstants.JEECG_EXCEL_VIEW;}

转载于:https://www.cnblogs.com/bridgestone29-08/p/11017617.html

jeecg导出Excel相关推荐

  1. jeecg导出excel设置样式XLS(03)与XLSX(07)

    jeecg版本依赖 <modelVersion>4.0.0</modelVersion><groupId>org.jeecgframework.boot</g ...

  2. jeecg中excel导出字段判空处理

    jeecg中excel导出字段判空处理 我们清楚,jeecg 导出 excel 采用的是 easypoi,不知道是否遇到过这种情况: 我们以一个实体属性为例: @Excel(name="问题 ...

  3. jeecg输入中文查询导表为空_JEECG 通用数据库导入导出excel

    需求:在实际J2EE项目中,经常遇到需要导入导出excel文件的情况: 解决方案: 利用java的annotation,自定义一个annotation ,在声明pojo的时候对需要操作字段的属性进行声 ...

  4. bootstraptable导出excel独立使用_使用 EasyPOI 优雅导出Excel模板数据(含图片)

    EasyPOI功能如同名字Easy,主打的功能就是容易,让一个没接触过POI的人员可以方便的写出Excel导出,Excel模板导出,Excel导入,Word模板导出.通过简单的注解和模板语言(熟悉的表 ...

  5. 使用EasyPOI导出Excel模板数据(含图片)

    使用EasyPOI导出Excel模板数据(含图片) EasyPOI功能如同名字Easy,主打的功能就是容易,让一个没接触过POI的人员可以方便的写出Excel导出,Excel模板导出,Excel导入, ...

  6. 使用EasyPoi导入导出Excel

    easypoi功能如同名字easy,主打的功能就是容易,让一个没见接触过poi的人员 就可以方便的写出Excel导出,Excel模板导出,Excel导入,Word模板导出,通过简单的注解和模板 语言( ...

  7. Easypoi模版导出excel

    若您正在使用easypoi进行excel导出的话,希望这篇文章能帮到您. 该文章是使用easypoi得模版方式实现excel导出(目前是单sheet的导出), 若需要使用非模版形式导出多sheet得话 ...

  8. easypoi教程_easypoi导出Excel

    1.参考资料 EasyPoi教程:http://easypoi.mydoc.io/#text_197817 码云地址:https://gitee.com/jeecg/easypoi 如果遇到导入导出E ...

  9. java struts2 excel上传_Java Struts2 实现数据库数据导出Excel文件

    HTML: 导出 Struts.xml true application/vnd.ms-excel;charset=GBK excelStream attachment;filename=${file ...

  10. Java springMVC POI 导出 EXCEL

    2019独角兽企业重金招聘Python工程师标准>>> 思路 : 将需要导出的数据存放在一个List中 创建一个EXCEL表 注意 XSSFWorkbook 只能操作2007以上的版 ...

最新文章

  1. 从10亿光年到0.1飞米的世界 (经典!震撼!)
  2. 推荐JS插件:imagesLoaded,监测图片加载情况并提供相应的事件(加载成功/失败)...
  3. Undefined function 'adb' for input arguments of type 'double'.
  4. win7卡在正在启动windows界面_win7开机一直卡在欢迎界面如何解决?
  5. 使用HTML语法图文混排
  6. qmake,make,nmake
  7. android 应用升级,系统做了什么?
  8. delphi计算机语言排名,2020年3月TIOBE编程语言排行榜 Java继续蝉联榜首
  9. Python小甲鱼课后习题 乌龟吃小鱼
  10. 游戏启动流程的逆向分析与多开的实现
  11. jQuery基本操作--制作论坛发帖
  12. python decorate 的秘密
  13. 华硕主板无盘启动bios设置_华硕主板bios设置图解教程
  14. 高德地图-设置点标注的文本标签
  15. 重启Oracle数据库的操作步骤
  16. Excel RTD函数入门
  17. Sign in with Apple(苹果授权登陆) java jwt方式验证
  18. python爬取百度在线语音合成的音频
  19. 彻底解决不要脸的360更改浏览器主页【转载】
  20. 【图像隐藏】基于小波变换+SURF、RANSAC、LT码、CRC(循环冗余检验)码多种算法实现图像隐藏(抗多种攻击)matlab源码

热门文章

  1. 基于VisualStudio11开发Windows8的Metro sample讲解(1)MessageBox
  2. 博弈知识汇总(转自Tanky Woo),留着以后复习
  3. CSS实现文字竖排效果
  4. Python之常用模块(3)
  5. Codeforces Round #461 (Div. 2)B-Magic Forest+位运算或优雅的暴力
  6. mysql主从复制浅析(一)
  7. eclipse使用ant + ivy 配置项目jar包和依赖关系
  8. python - - 函数 - - 递归函数
  9. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp
  10. 阿里云智能图像识别服务发布