项目中的导出(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输出流的时候就出错了. 造成关闭流的主要原因有时其实是跨域,同域是没有问题的. //新建 ...
随机推荐
- 洛谷 [P1024]一元三次方程求解
一道水题然而坑点很多. #include <iostream> #include <cstdio> #include <algorithm> #include &l ...
- bzoj 4815: [Cqoi2017]小Q的表格 [数论]
4815: [Cqoi2017]小Q的表格 题意: 单点修改,查询前缀正方形和.修改后要求满足条件f(a,b)=f(b,a), b×f(a,a+b)=(a+b)*f(a,b) 一开始sb了认为一次只会 ...
- 使用Python的requests库进行接口测试——session对象的妙用
from:http://blog.csdn.net/liuchunming033/article/details/48131051 在进行接口测试的时候,我们会调用多个接口发出多个请求,在这些请求中有 ...
- 撸一撸Spring Cloud Ribbon的原理
说起负载均衡一般都会想到服务端的负载均衡,常用产品包括LBS硬件或云服务.Nginx等,都是耳熟能详的产品. 而Spring Cloud提供了让服务调用端具备负载均衡能力的Ribbon,通过和Eure ...
- 【技术干货】git常用命令
2.1 git init语法: git init在当前目录初始化git仓库,适用于尚未使用git管理的项目2.2 git clone语法: git clone <url>例如: git c ...
- 使用单元素的枚举类型实现Singleton
从java1.5版本开始,实现singleton出现了第三种方式: public enum SingleTon { INSTANCE; public void speak() { System.out ...
- python使用
1. ipython 打印所有的输出变量 from IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast ...
- 上帝之眼APP——实时定位监控、即时通讯
项目地址 https://github.com/guoyaohua/GodsEYE 开发环境 Android studio 2.3.1 极光推送IM SDK 百度鹰眼SDK 背景介绍 定位监控系统,不 ...
- GB 标准
std::map<int, std::string> GB2261 = { { 0,"未知的性别" }, { 1,"男性" }, { 2," ...
- Google 浏览器被劫持怎么办?
chrome://version/ 输入以上语句,在命令行中可看到恶意网址,复制该命令行,修改后面的网址即可