导出下载多个Excel文件并打包成zip文件
来源:互联网 发布:2012年cba总决赛数据 编辑:程序博客网 时间:2024/05/27 01:11
导出下载单个Excel也许简单,但是有的时候也会用到下载多个excel并且打包成zip文件的情况,最近遇到了,现在简单整理一下!
1、ftl文件
<a class="btn " type="button" onclick="exportSelectExcel()"><i class="fa fa-share-square-o text-olive"> </i> 导出</a>
<table id="annualPlanTable" class="table table-striped table-hover" data-sort-name="createTime" data-order-name="desc" data-toggle="table" data-url="listManage_sgJSONData" data-query-params="getBootstrapTableParams" data-side-pagination="server" data-pagination="true" ><thead><tr><span style="white-space:pre"></span><th data-checkbox="true"></th><th data-field="planName" data-formatter="planNameFormatter">名称</th><th data-field="planNo">计划编号</th><th data-field="version">版本编号</th><th data-field="commandName">指挥部</th><th data-field="sectionName">标段</th><th data-field="createTime" data-formatter="GT.BootStrap.formatToYYYYMMDD">提报时间</th><th data-field="entrPsnName">提报人</th><th data-field="status">审核状态</th><th data-field="operation" data-formatter="operationFormatter">操作</th></tr></thead> </table>
2、js文件
//导出中function exportSelectExcel(){var checkedData = GT.BootStrap.checkDataIdsToBootstrap("annualPlanTable");if (checkedData==0) { gAlert("请至少择一个要导出的项目","友情提示");return;}exportPlanMaterialExcelById(checkedData);}function exportPlanMaterialExcelById(checkedData){if(checkedData){var url = BASEUrl+"exportPlanMaterialExcelById?ids="+checkedData;window.open(url);}}
3、controller方法
import com.gt.util.common.ExcelImport;import com.gt.util.common.FileDownloadBean;import com.gt.util.common.FileDownloadUtil;import com.gt.util.common.FileDownloadZipUtil;
/** * 导出需求计划中的物资信息 * @param request * 中ids 每一个需求计划导出一个excel * @param request * @param response * @throws IOException */@RequestMapping(value = "/exportPlanMaterialExcelById")public void exportPlanMaterialExcelById(@RequestParam(value = "ids") String ids,HttpServletRequest request, HttpServletResponse response)throws IOException {try {List<FileDownloadBean> fileDownloadBeans=new ArrayList<FileDownloadBean>();List<Long> idArry=stringToLongList(ids);for (Long id : idArry) {FileDownloadBean fileDownloadBean=<span style="color:#ff0000;">createFileDownloadBean</span>(request, response, id, null);fileDownloadBeans.add(fileDownloadBean);}FileDownloadZipUtil.downLoadExcelToZip(fileDownloadBeans,"全线年度需求计划",request, response);} catch (Exception e) {log.error("全线/需求计划管理页-导出需求计划中的物资信息报错。" + e.getMessage(),e);}}
/** * * <构造下载所需的javabean> * <功能详细描述> * @author XXX * @date 2016年5月28日 * @param request * @param response * @param blngsPtbId * @param searchMaterialParams * @return */@SuppressWarnings({"rawtypes" })private FileDownloadBean <span style="color:#ff0000;">createFileDownloadBean</span>(HttpServletRequest request,HttpServletResponse response,Long blngsPtbId,String searchMaterialParams){ FileDownloadBean fileDownloadBean=new FileDownloadBean();try { DemandSupplyPlanVO demandSupplyPlanVO = demandSupplyPlanService.getById(blngsPtbId);BootstrapPager pager=new BootstrapPager();pager.setlimit(Integer.MAX_VALUE);List<DemandSupplyMaterialVO> demandSupplyMaterials=demandSupplyMaterialService.findByBlngsPtbId(pager, blngsPtbId, searchMaterialParams).getRows();String path = null;if(demandSupplyPlanVO.getPlanTypeCde().getCode()==PlanType.All.getCode()){path = request.getServletContext().getRealPath("/excel") + "/"+EXCEL_TEMPLATE_FILENAME_ALL+".xls";}else if(demandSupplyPlanVO.getPlanTypeCde().getCode()==PlanType.YEAR.getCode()){path = request.getServletContext().getRealPath("/excel") + "/"+EXCEL_TEMPLATE_FILENAME_YEAR+".xls";}String fileName = demandSupplyPlanVO.getSectionName()+"标段的"+demandSupplyPlanVO.getPlanName()+"物资";fileDownloadBean.setFileName(fileName);fileDownloadBean.setPath(path);fileDownloadBean.setRs(demandSupplyMaterials);fileDownloadBean.setExtendsName(".xls");} catch (Exception e) {log.error("全线年度需求计划-导出物资报错。" + e.getMessage(),e);}return fileDownloadBean;}
4、需要的jar文件,以及xls文件
打包zip下载Excel文件 (提取码:5188)
2 0
- 导出下载多个Excel文件并打包成zip文件
- struts zip打包多个文件并下载
- 打包zip文件并下载
- java实现word下载及打包成zip下载(单个文件、多个文件)
- java实现文件自动打包成zip并下载…
- java 生成多个excel文件并打成zip包供用户下载
- 把数据量大导出 放入多个excel 然后压缩成zip文件,导出
- java的多个excel打包成zip下载
- 10月19_大数据导出多张excel表并打包成zip包下载
- spring mvc java 把多文件打包成zip,并下载
- spring mvc java 把多文件打包成zip,并下载
- 把多个文件打包压缩成ZIP文件
- 批量将报表导成excel文件并打包下载
- 多文件打包rar或者zip下载
- Struts2多文件zip打包下载
- 导出excel文件 导出zip文件
- JAVA 根据Url把多文件打包成ZIP下载
- 下载文件打包 zip java
- 深度学习调参技巧
- linux用户,分组,权限,文件权限
- [leetcode] 【字符串】 14. Longest Common Prefix
- windows 安装subversion1.9.4及配置
- html中button的立体效果圆角
- 导出下载多个Excel文件并打包成zip文件
- java中form以post、get方式提交数据中文乱码问题总结
- 八、Linux源码包编译和安装
- 基于原生Canvas来绘制的各种图表
- 抓包工具,查看浏览器缓存的密码以及网络密码
- 用IBM Bluemix搭建云平台流程
- git&github使用笔记(一)——Git建立本地库,并上传Github
- ccah-500 第34题 you want to change a configuration parameter so that it affects all six DataNodes
- 重建二叉树