项目中的导出(jxl插件)
第一步,获取要导出的参数,为导出做准备
public ModelAndView downloadInfo(final HttpServletRequest request, final HttpServletResponse response) throws Exception { List2ExcelHelper list2ExcelHelper = new List2ExcelHelper(); String orderId = request.getParameter("orderId"); // 工单 String idContent = request.getParameter("idContent"); String memcode = request.getParameter("memberCode"); String merchantName = request.getParameter("merchantName"); String flowNodeId = request.getParameter("flowNodeId"); // 流程+节点+产品编码 String orderType = request.getParameter("orderType"); // String merchantLevel = request.getParameter("merchantLevel"); // 产品 String startDate = request.getParameter("startDate"); String endDate = request.getParameter("endDate"); String flowId = flowNodeId.split(";")[0]; String nodeId = flowNodeId.split(";")[1]; String productCode = flowNodeId.split(";")[2]; Map<String, String> params = new HashMap<String, String>(); String[] flowIds = null; List<ExcelShellProperty> list = new ArrayList<ExcelShellProperty>(); if (!StringUtil.isEmpty(orderId)) { params.put("orderId", orderId); } if (!StringUtil.isEmpty(memcode)) { params.put("memcode", memcode); } if (!StringUtil.isEmpty(idContent)) { params.put("idContent", idContent); } if (!StringUtil.isEmpty(merchantName)) { params.put("merchantName", merchantName); } if (!StringUtil.isEmpty(merchantLevel)) { params.put("merchantLevel", merchantLevel); } params.put("flowNodeId", flowNodeId); params.put("orderType", orderType); flowIds = flowId.split(","); params.put("flowId", flowId); params.put("nodeId", nodeId); params.put("productCode", productCode); if (!StringUtil.isEmpty(startDate)) { params.put("startDate", startDate); } if (!StringUtil.isEmpty(endDate)) { params.put("endDate", endDate); } ManualOpenService manualOpenService = manualOpenFactory.getManualOpenService(params); if (manualOpenService == null) { return index(request, response); } for(String qryFlowId :flowIds) { params.put("flowId", qryFlowId); List<ExcelShellProperty> qryList = new ArrayList<ExcelShellProperty>(); 56 qryList = manualOpenService.getDownLoadList(params); if(!list.isEmpty()) { for(ExcelShellProperty espList:list) { for(ExcelShellProperty qryEspList:qryList) { List tempEspList = new ArrayList(); if(espList.getSheetName().equals(qryEspList.getSheetName())){ for(Object obj:qryEspList.getDataList()){ if(!espList.getDataList().contains(obj)){ tempEspList.add(obj); } } } if(!tempEspList.isEmpty()) { espList.getDataList().addAll(tempEspList); } } } }else { list.addAll(qryList); } } String downLoadName = flowNodeId; NodeRole nodeRole = new NodeRole(); nodeRole.setFlowId(flowId); nodeRole.setNodeId(nodeId); nodeRole = nodeRoleService.findNodeRoleByModel(nodeRole); if (nodeRole != null) { downLoadName = manualOpenService.generateDownloadName(request, nodeRole.getNodeDesc()); } list2ExcelHelper.downLoad("商户信息", list, response, downLoadName); return null; }
其中最主要的就是这个qryList
qryList就是下面代码封装的东西。
封装信息一:EXLPROPERTIES
[工单详情ID, 订单编号, 客户名称, 快钱账户, 商户编号, SDK聚合支付, 微信APP支付%, 支付宝APP支付(标准版)%, 支付宝APP支付(定制版)%, 飞凡通APP支付%, 移动网关, 微信公众号支付, 公众号appid, 公众号appid费率, 微信WAP支付%, 支付宝服务窗支付%, 支付宝WAP支付(标准版)%, 支付宝WAP支付(定制版)%, 飞凡通H5支付%, 备注]
封装信息二:EXLCOLVIEW
[orderId, crmOrderId, merchantName, idContent, assetCode, SDKAggregationPayment, WXOrdinaryRate, ZhiFuBaoSOrdinaryRate, ZhiFuBaoCOrdinaryRate, SPAOrdinaryRate, MobileGateway, WeiXinPublicPayment, PublicNumberAppId, PNAOrdinaryRate, WXWPOrdinaryRate, ASWPOrdinaryRate, AWPSOrdinaryRate, AWPCOrdinaryRate, FFH5POrdinaryRate, Remark]
封装信息三:CRM-无卡支付移动支付信息
封装信息四:最主要的,从数据库动态获取的。下面是取了一个静态的作为案例的讲解
openMPWMapList
[{SPAOrdinaryRate=1, authorizeNum=null, merchantFinanceTmp=null, PublicNumberAppId=, creater=default_crm, bankProvince=null, WXWPOrdinaryRate=, city=澳门市, partnerid=null, saler=null, financeName=341321, PNAOrdinaryRate=, businessArea=, brandLicense=null, orgCode=null, merchantType=0, WXOrdinaryRate=, mainProductService=, SDKAggregationPayment=是, registCode=null, memberCode=10012400238, legalName=刘淑敏, statusLevel2=1, businessScope=null, unionPay=0, mainUsers=null, bankName=null, businessType=3, nullName=刘淑敏, postcode=null, manualDowngrade=0, channelShortName=春秋test01, ext3=null, callName=341321, salerDomainName=sunny.han, relationType=null, industryCode=301001, assetCode=812320047220019, externalId=15137639706423110, isBlack=0, merchantFinance={applyId=1712201755497668, billShareAmount=null, merchantsRegistratioId=null, billMailSendCont=2389472374@qq.com, contractIsExt=1, goalDescription=null, oppId=null, id=3385, discountReasonDescribe=null, crmOrderId=null, description=null, oppName=null, billAccountShareAmount=null, sendMailWay=1, createDate=1513763935000, merchantCode=3021729, fgpa=null, oldOppId=null, predictDate=null, payment=客户线下付款或返还, contractUniformSend=1, orderField=null, invoiceType=增值税普通发票, useDeposit=null, PayAfterReceive=null, goal=null, paymentLink=null, webphoneOrderNumber=null, contractNotstandOa=null, contractSuppleOa=null, discountReason=null, deliveryStatus=1, billContractEndDate=2018-12-19, bankAccount=null, billContractStartDate=2017-12-20}, businessTelephone=13721241234, mobilephone=13721241234, frontHelper=danny.huang, squareName=null, subjectType=, businessEmail=test0080201@qq.com, grade=普通, clueProvider=, statusLevel1=null, createDate=2017-12-20 18:04:37, changeList=, expectedAvgMonthlyAmount99Bill=, merchantCode=3021729, orderId=17698709, channelName=春秋航空公司test01, multiAssetTag=0, itemStatus=0, registFund=null, salerId=21705, foundDate=null, financeEmail=test0080201@qq.com, callTelephone=13721241234, authfileStatus=0, method=save, custBgIntroduction=, cardDesc=null, applyDetailId=7210226650, constraintBusiness=百货, telephone=null, bankBranch=null, isWdBusinessCircle=0, accessType=首选, nullEmail=201712081453test@163.com, merchantAlias=434, orgBelongto=null, productScope=营销产品[预付卡];金融产品[信用支付];支付产品[CP刷卡支付, 终端, 提现&定向付款, 电子付款, 无卡支付, 人民币网关, 移动支付, 账户支付(飞凡通), 静态码], businessName=341321, remark=, nullTelephone=13721241234, financeTelephone=13721241234, isUniformSocialCredit=null, ZhiFuBaoSOrdinaryRate=, ZhiFuBaoCOrdinaryRate=, bankNo=null, custIndustryStatus=, assetsSerial=DSCNMPW100115442027210226650, industryParentType=3, workOrderType=订单新增, shareMargin=, callEmail=test0080201@qq.com, province=澳门特别行政区, handleDate=null, applydetailId=7210226650, squareType=null, custSaleModel=, FFH5POrdinaryRate=2, capitalPaid=, ASWPOrdinaryRate=, bankCity=null, expectedAvgMonthlyAmount=, clueSource=, cardType=1, email=201712081453test@163.com, billAccountType=0, parentAssetsSerial=DSCNP100115442027210226648, websiteMerchantType=0, customerStatus=潜在, idContent=2389472374@qq.com, SpecialPassAPPPay=1, merchantSource=null, parentCustcode=812110053000029, operationTime=0.0, merchantShortName=null, childrenCustomer=0, registDate=null, crmOrderId=1712201755497668, area=null, cancelDate=null, merchantName=无卡支付00053, legalId=432477777444444, parentCustname=, expectedAvgTransactionValue=, FeiFanH5Pay=1, busiPropertyBelongto=1, cpAreaCode=11111111, AWPCOrdinaryRate=, legalSex=0, identityType=null, registAddress=null, industrySubType=19, custAnnualSales=, workOrderId=24319, productCode=DSCNMPW, website=null, batchOrder=null, otherInfo=null, MobileGateway=是, headquarters=账户转移商户A02, saleOrg=1, keyCustomer=0, categorys=null, isChannelCustomer=null, address=澳门特别行政区安徽省安庆市江苏无锡, businessRegno=45234523, clueConnSituation=, companyType=有限责任公司, businessFormat=null, Remark=, AWPSOrdinaryRate=, customerBrand=, employees=0, ffanDept=null}, {SPAOrdinaryRate=3, authorizeNum=null, merchantFinanceTmp=null, PublicNumberAppId=, creater=default_crm, bankProvince=null, WXWPOrdinaryRate=, city=澳门市, partnerid=null, saler=null, financeName=caiwu1, PNAOrdinaryRate=, businessArea=, brandLicense=null, orgCode=null, merchantType=0, WXOrdinaryRate=, mainProductService=, assetsNumToShow=, SDKAggregationPayment=是, registCode=null, memberCode=10012400246, legalName=刘淑敏, statusLevel2=1, businessScope=null, unionPay=0, mainUsers=null, bankName=null, businessType=3, nullName=hetong1, postcode=null, manualDowngrade=0, channelShortName=春秋test01, ext3=null, callName=tiaodan1, salerDomainName=sunny.han, relationType=null, industryCode=301002, assetCode=812320047220019, externalId=15138254313089911, isBlack=0, merchantFinance={applyId=1712211059427651, billShareAmount=null, merchantsRegistratioId=null, billMailSendCont=3872385792378@qq.com, contractIsExt=1, goalDescription=null, oppId=null, id=3394, discountReasonDescribe=null, crmOrderId=null, description=null, oppName=null, billAccountShareAmount=null, sendMailWay=1, createDate=1513825388000, merchantCode=3021737, fgpa=null, oldOppId=null, predictDate=null, payment=客户线下付款或返还, contractUniformSend=1, orderField=null, invoiceType=增值税普通发票, useDeposit=null, PayAfterReceive=null, goal=null, paymentLink=null, webphoneOrderNumber=null, contractNotstandOa=null, contractSuppleOa=null, discountReason=null, deliveryStatus=1, billContractEndDate=2018-12-20, bankAccount=null, billContractStartDate=2017-12-21}, businessTelephone=13721241234, mobilephone=13721241234, frontHelper=danny.huang, squareName=null, subjectType=, businessEmail=shangwu0080201@qq.com, grade=普通, clueProvider=, statusLevel1=null, createDate=2017-12-21 11:05:07, changeList=, expectedAvgMonthlyAmount99Bill=, merchantCode=3021737, orderId=17698730, channelName=春秋航空公司test01, multiAssetTag=0, itemStatus=0, registFund=null, parentAssetsNumToShow=812320047220019, salerId=21705, foundDate=null, financeEmail=caiwu0080201@qq.com, callTelephone=13721241234, authfileStatus=0, method=save, custBgIntroduction=, cardDesc=null, applyDetailId=7210226680, constraintBusiness=百货, telephone=null, bankBranch=null, isWdBusinessCircle=0, accessType=首选, nullEmail=test0080201@qq.com, merchantAlias=434, orgBelongto=null, productScope=营销产品[预付卡];金融产品[信用支付];支付产品[CP刷卡支付, 终端, 提现&定向付款, 电子付款, 无卡支付, 人民币网关, 移动支付, 账户支付(飞凡通), 静态码], businessName=shangwu1, remark=, nullTelephone=13721241234, financeTelephone=13721241234, isUniformSocialCredit=null, ZhiFuBaoSOrdinaryRate=, ZhiFuBaoCOrdinaryRate=, bankNo=null, custIndustryStatus=, assetsSerial=DSCNMPW100115442027210226680, industryParentType=3, workOrderType=订单新增, shareMargin=, callEmail=tiaodan0080201@qq.com, province=澳门特别行政区, handleDate=null, applydetailId=7210226680, squareType=null, custSaleModel=, FFH5POrdinaryRate=4, capitalPaid=, ASWPOrdinaryRate=, bankCity=null, expectedAvgMonthlyAmount=, clueSource=, cardType=1, email=201712081453test@163.com, parentAssetsId=4380639, billAccountType=0, parentAssetsSerial=DSCNP100115442027210226663, websiteMerchantType=0, customerStatus=正式, idContent=3872385792378@qq.com, SpecialPassAPPPay=1, merchantSource=null, parentCustcode=812110053000029, operationTime=0.0, merchantShortName=null, childrenCustomer=0, registDate=null, crmOrderId=1712211059427651, area=null, cancelDate=null, merchantName=无卡支付00054, legalId=2342342342, parentCustname=, expectedAvgTransactionValue=, FeiFanH5Pay=1, busiPropertyBelongto=1, cpAreaCode=11111111, AWPCOrdinaryRate=, legalSex=0, identityType=null, registAddress=null, industrySubType=20, custAnnualSales=, workOrderId=24332, productCode=DSCNMPW, website=null, batchOrder=1, otherInfo=null, MobileGateway=是, headquarters=账户转移商户A02, saleOrg=1, keyCustomer=0, categorys=null, isChannelCustomer=null, address=澳门特别行政区安徽省安庆市江苏无锡, businessRegno=342342, clueConnSituation=, companyType=有限责任公司, businessFormat=null, Remark=, AWPSOrdinaryRate=, customerBrand=, employees=0, ffanDept=null}]
@Override public List<ExcelShellProperty> getDownLoadList(Map params) throws Exception { List<Map<String, Object>> openMPWMapList = getDetailListForDownLoad(params); if (CollectionUtils.isNotEmpty(openMPWMapList)) { for (Map<String, Object> openMPWMap : openMPWMapList) { setAccountDefaultData(openMPWMap); } } List<ExcelShellProperty> list = new ArrayList<ExcelShellProperty>(); ExcelShellProperty excelShellProperty = new ExcelShellProperty(); excelShellProperty.setSheetName("CRM-无卡支付移动支付信息"); excelShellProperty.setColProperties(EXLPROPERTIES); excelShellProperty.setColView(EXLCOLVIEW); excelShellProperty.setDataList(openMPWMapList); list.add(excelShellProperty); return list; }
public class ExcelShellProperty { private String[] colProperties; private String[] colView; private String sheetName; private List dataList; public String[] getColProperties() { return colProperties; } public void setColProperties(String[] colProperties) { this.colProperties = colProperties; } public String[] getColView() { return colView; } public void setColView(String[] colView) { this.colView = colView; } public String getSheetName() { return sheetName; } public void setSheetName(String sheetName) { this.sheetName = sheetName; } public List getDataList() { return dataList; } public void setDataList(List dataList) { this.dataList = dataList; } }
private static final String[] EXLPROPERTIES = {"orderId", "crmOrderId", "merchantName", "idContent" , "assetCode","SDKAggregationPayment","WXOrdinaryRate", "ZhiFuBaoSOrdinaryRate", "ZhiFuBaoCOrdinaryRate", "SPAOrdinaryRate", "MobileGateway" ,"WeiXinPublicPayment", "PublicNumberAppId", "PNAOrdinaryRate","WXWPOrdinaryRate","ASWPOrdinaryRate","AWPSOrdinaryRate","AWPCOrdinaryRate", "FFH5POrdinaryRate","Remark"}; private static final String[] EXLCOLVIEW = { "工单详情ID", "订单编号", "客户名称", "快钱账户", "商户编号", "SDK聚合支付", "微信APP支付%", "支付宝APP支付(标准版)%", "支付宝APP支付(定制版)%", "飞凡通APP支付%", "移动网关", "微信公众号支付", "公众号appid","公众号appid费率", "微信WAP支付%", "支付宝服务窗支付%", "支付宝WAP支付(标准版)%", "支付宝WAP支付(定制版)%", "飞凡通H5支付%", "备注" };
第二步:插件的应用
public void downLoad(String dealType, List<ExcelShellProperty> sheets, HttpServletResponse response, String fileName) { WritableWorkbook book = null; ByteArrayOutputStream baos = null; ServletOutputStream out = null; if (sheets.size() == 0) { return; } try { baos = new ByteArrayOutputStream(); // 打开文件,baos可以是一个字节流也可以是一个路径,baos一开始是一个null对象,下面通过book一直往里面添加东西,最后这个对象里面就有东西了。 book = Workbook.createWorkbook(baos); int sheetNo = 1; for (ExcelShellProperty excelShellProperty : sheets) { //就是excel表格的sheet那里写的信息,默认的是sheet,sheet1等 //sheetNo是第几个excel表格 WritableSheet sheet = book.createSheet(excelShellProperty.getSheetName(), sheetNo); WritableCellFormat format = new WritableCellFormat(); //WritableCellFormat处代码使用了WritableCellFormat类,这个类非常重要,通过它可以指定单元格的各种属性,后面的单元格格式化中会有更多描述。 format.setAlignment(Alignment.CENTRE); format.setVerticalAlignment(VerticalAlignment.CENTRE); format.setBackground(Colour.BLUE); Label label = null; WritableFont wf = new WritableFont(WritableFont.TAHOMA); wf.setColour(Colour.BLUE); wf.setPointSize(12); WritableCellFormat wcfF = new WritableCellFormat(wf); //colView获取第一行的内容,并且是带有格式的 String[] colView = excelShellProperty.getColView(); int i = 0; for (int len = colView.length; i < len; ++i) { label = new Label(i, 0, colView[i], wcfF); sheet.setColumnView(i, 25); sheet.addCell(label); } setExcelBody(excelShellProperty.getDataList(), excelShellProperty.getColProperties(), label, sheet); sheetNo++; } book.write(); book.close(); book = null; response.setContentType("application/vnd.ms-excel;charset=gb2312"); response.setHeader("Content-disposition", "attachment; filename=" + new String(fileName.getBytes("gb2312"), "ISO8859-1" )+".xls"); response.setContentLength(baos.size()); out = response.getOutputStream(); baos.writeTo(out); out.flush(); out.close(); } catch(Exception e) { log.error("List2ExcelHelper downLoad" , e); } finally { try { if (baos != null) baos.close(); if (book != null) book.close(); if (out != null) out.close(); } catch(Exception e2) { e2.printStackTrace(); } } }
public void setExcelBody(List massList, String[] colProperties, Label label, WritableSheet sheet1) throws WriteException { int i = 0; for (int len = massList.size(); i < len; ++i) { //获取第2,3,4。。。。。行第一列的内容 Map listOrderMap = (Map) massList.get(i); String cont = listOrderMap.get(colProperties[0])== null?"":listOrderMap.get(colProperties[0]).toString(); label = new Label(0, i + 1, cont); sheet1.addCell(label); int j = 1; for (int length = colProperties.length; j < length; ++j) {//获取第2,3,4。。。。。行第二列以后的内容 label = new Label(j, i + 1, getObjectStr(listOrderMap.get(colProperties[j]))); sheet1.addCell(label); } } }
效果展示:
项目中的导出(jxl插件)的更多相关文章
- 如何在实际项目中使用PageHelper分页插件
PageHelper是一个分页插件,能够简单快速的帮助开发人员完成常见的分页功能,你只需要简单的使用两行代码就可以完成一个分页效果- 最近做一个科创项目,使用Maven+SSM的环境,有分页的功能,于 ...
- 项目中 poi 导出 出现html特殊符号的实体 (已解决)
导出excel 时出现 类似这样的> 符号 , 大概是存到数据库也是这样,然后jsp解析可以解析出来,但是java不认得,需要个人写出解析方法. 废话不说,贴码: /** *转换html特殊符 ...
- Npoi Web 项目中(XSSFWorkbook) 导出出现无法访问已关闭的流的解决方法
原本在CS项目中用的好好的在BS项目中既然提示我导出出现无法访问已关闭的流的解决方法 比较郁闷经过研究 终于解决了先将方法发出来 让遇到此问题的筒子们以作参考 //新建类 重写Npoi流方法 publ ...
- 项目中遇到angular时间插件datetinepicker汉化问题
问题描述: 测试需要中文的时间插件: 参考资料: angularjs封装bootstrap官网的时间插件datetimepicker https://www.cnblogs.com/cynthia-w ...
- vue项目中,使用vue-awesome-swiper插件实现轮播图
一.安装 npm install vue-awesome-swiper 二.项目中引入 import 'swiper/dist/css/swiper.css'import {swiper,swiper ...
- maven项目中添加Tomcat启动插件
在pom.xml文件中添加如下配置: <!-- 配置tomcat插件,pom.xml里配置 --> <build> <plugins> <plugin> ...
- 在MVC项目中分页使用MvcPager插件
参考网站 http://www.webdiyer.com/mvcpager/demos/ 这个插件非常简单易用,如果想快速使用 可以参考我这篇文章,其实参考网站也是非常简单的 首先选择你的web项目 ...
- vue 项目中运用到的插件 或者依赖安装
1.安装less ,less-load npm install less less-loader --save-dev 2.安装vux npm install vux --save npm insta ...
- Npoi Web 项目中(XSSFWorkbook) 导出出现无法访问已关闭的流
NPOI生产.xlsx文件件时,在使用book.Write(ms);后,会关闭流,这样导致再次使用Respons输出流的时候就出错了. 造成关闭流的主要原因有时其实是跨域,同域是没有问题的. //新建 ...
随机推荐
- BZOJ 1758: [Wc2010]重建计划 [暂时放弃]
今天晚上思维比较乱,以后再写写吧#include <iostream> #include <cstdio> #include <cstring> #include ...
- HDU 3949 XOR [高斯消元XOR 线性基]
3949冰上走 题意: 给你 N个数,从中取出若干个进行异或运算 , 求最后所有可以得到的异或结果中的第k小值 N个数高斯消元求出线性基后,设秩为$r$,那么总共可以组成$2^r$中数字(本题不能不选 ...
- 汇编语言2(mooc)
伪指令没有:冒号.
- Flask-Moment----探索
前言: Flask-Moment在所有的flask扩展中算是相对简单的一个了,但是还是有很多需要理解的地方.那么今天就跟着笔者一起,来学习一下flask-moment在flask项目中的应用. 首先 ...
- mongodb window安装配置
下载mongodb安装包 1. https://www.mongodb.org/dl/win32/x86_64-2008plus-ssl?_ga=2.233271640.711265466.15193 ...
- centos ELK安装
本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn ELK是进行日志收集分析用的,具体工作.原理.作用自行google. ...
- [NOIP2001提高组]数的划分
题目描述 将整数n分成k份,且每份不能为空,任意两个方案不相同(不考虑顺序). 例如:n=7,k=3,下面三种分法被认为是相同的. 1,1,5; 1,5,1; 5,1,1; 问有多少种不同的分法. 输 ...
- Zabbix 3.2.4至3.2.7的升级方案
1.关闭Zabbix Server 防止有新的数据提交到数据库中,也可以关闭数据库.如果更新过程中,评估告警信息可以忽略,可以先执行备份操作. 1.1.检查当前版本 /usr/local/zabbix ...
- JavaScript面向对象学习笔记
JavaScript 常被描述为一种基于原型的语言 (prototype-based language)--每个对象拥有一个原型对象,对象以其原型为模板.从原型继承方法和属性.原型对象也可能拥有原型, ...
- hbase优化之region合并和压缩
HBASE操作:(一般先合并region然后再压缩) 一 .Region合并: merge_region 'regionname1','regionname2' ,'true' --true代表 ...