java导出列表到Excel,注意是xls格式

页面展示:

 

页面的JS:

//导出
	function exportExDownload(){
		var ccb004=$("#ccb004").val();
		if(undefined==ccb004){ccb004="";}
		var ccb005 =$("#ccb005").val();
		if(undefined==ccb005){ccb005="";}
		var ccb015 =$("#ccb015").val();
		if(undefined==ccb015){ccb015="";}
		var ccb017 =$("#ccb017").val();
		if(undefined==ccb017){ccb017="";}
		var dateSta =$("#dateSta").val();
		if(undefined==dateSta){dateSta="";}
		var dateEnd =$("#dateEnd").val();
		if(undefined==dateEnd){dateEnd="";}
		var ccb006 =$("#ccb006").val();
		if(undefined==ccb006){ccb006="";}
		var ccb016 =$("#ccb016").val();
		if(undefined==ccb016){ccb016="";}
		var ssq =$("#ssq").val();
		if(undefined==ssq){ssq="";}
		location.href="${ctx}/business/front/empc/bback/exportExDownload.xhtml?ccb004="+ccb004
		+"&ccb015="+ccb015
		+"&ccb017="+ccb017
		+"&dateSta="+dateSta
		+"&dateEnd="+dateEnd
		+"&ccb006="+ccb006
		+"&ccb016="+ccb016
		+"&ssq="+ssq;
	}

后台controller:

@SuppressWarnings("unchecked")
	@RequestMapping("/exportExDownload")
	public ModelAndView exportExDownload(Tbfback input,
			ModelMap model, Page page, HttpServletRequest request,
			HttpServletResponse response) throws IOException {
		
		page.setPageSize(5000);//如果数据过多,设置最大导出数据量
        //需要导出的业务数据
		List<Tbfback> dataList = tbfbackService.getByPage(input, page);
		if(dataList.size()>0){
			List<Dictionary> EMPC_BZFKTJ = businessDirectoryService
					.getDirectoryListUseCategory(DirectoryCategory.EMPC_BZFKTJ);
			String ccb006Str = "JY_FBACK";
			if(null!=input&&StringUtils.isNotEmpty(input.getCcb017())){
				ccb006Str = ccb006Str+input.getCcb017();
			}	
			List<Dictionary> JY_FBACK = businessDirectoryService
					.getDirectoryListUseCategory(ccb006Str);
			//循环数据进行字典转换
			for(Tbfback data:dataList){
				//问题类型
				if(StringUtils.isNotBlank(data.getCcb006())){
					for(Dictionary di:JY_FBACK){
						if(data.getCcb006().equals(di.getVal())){
							data.setCcb006(di.getName());
						}
					}
				}
				//所属区
				if(StringUtils.isNotBlank(data.getCcb006())){
					for(Dictionary di:aab301List){
						if(di.getVal().equals(data.getSsq())){
							data.setSsq(di.getName());
						}
					}
				}
				//状态 ccb005
				if(StringUtils.isNotBlank(data.getCcb006())){
					for(Dictionary di:EMPC_BZFKTJ){
						if(data.getCcb005().equals(di.getVal())){
							data.setCcb005(di.getName());
						}
					}
				}
			}
		}
		
		ExcelDataControl excelDataControl = new JxlExcelDataControl();
		String contentType = "application/x-download";
		String realName = "messageDetailList.xls";
		FileOperateUtil.downloadOutputStreamSet(request, response, contentType,
				realName);
		String configPath = CfcFilePathHelp.getRealPath()
				+ "WEB-INF/uploadconfig/foundationcentre/config/messageDetailList.xml";
		excelDataControl.loadConfig(new File(configPath));
		String templatePath = CfcFilePathHelp.getRealPath()
				+ "WEB-INF/uploadconfig/foundationcentre/template/messageDetailList.xls";
		excelDataControl.loadWriterWorkBook(new File(templatePath), response
				.getOutputStream());
		excelDataControl.loadWriterSheets();
		excelDataControl.exportData(dataList);// 将数据写入Excel
		excelDataControl.close(); // 关闭相关文件
		excelDataControl.releaseProVals();
		
		int temp = dataList.size();
		logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>总计录数:" + temp);
		return null;
	}

将涉及的包文件放在百度云盘哦:链接: https://pan.baidu.com/s/1nOsVx5hO6GeN2tx2gTSnjA 提取码: prut 复制这段内容后打开百度网盘手机App,操作更方便哦

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值