导出数据 org.apache.poi.hssf.usermodel.HSSFWorkbook

		
		Map<String,Object> params = (Map<String, Object>) request.getSession().getAttribute(DOWNLOADPARAMSKEY);
		
		if(null == params){
			response.getWriter().print("error request");
			return;
		}
		
		String fileName = String.format("%s.xls", new Date().getTime());
		response.setContentType("application/octet-stream");
		response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
		
		List<ExportSigningInfo> applyInfoList = signingOnlineNewService.getExportSigningInfoList(params);
		log.info("data size:"+ applyInfoList.size());
		
		HSSFWorkbook book = new HSSFWorkbook();
		
		HSSFSheet sheet = book.createSheet("在线签约申请记录");
		sheet.setColumnWidth(0, 30 * 256); 
		sheet.setColumnWidth(1, 13 * 256); 
		sheet.setColumnWidth(2, 10 * 256); 
		sheet.setColumnWidth(3, 35 * 256); 
		sheet.setColumnWidth(4, 10 * 256); 
		sheet.setColumnWidth(5, 10 * 256); 
		sheet.setColumnWidth(6, 20 * 256); 
		sheet.setColumnWidth(7, 10 * 256); 
		sheet.setColumnWidth(8, 20 * 256); 
		sheet.setColumnWidth(9, 10 * 256); 
		sheet.setColumnWidth(10, 10 * 256); 
		sheet.setColumnWidth(11, 12 * 256); 
		sheet.setColumnWidth(12, 10 * 256); 
		sheet.setColumnWidth(13, 10 * 256); 
		
		HSSFRow titleRow = sheet.createRow((short)0);

		CellStyle titleStyle = getTitleStyle(book);
		for (int i = 0; i < TITLES.length; i++) {
			HSSFCell cell = titleRow.createCell(i);
			cell.setCellStyle(titleStyle);
			cell.setCellValue(TITLES[i]);
		}
		
//		CellStyle gridStyle = getRowStyle(book);
		for (int i = 0; i < applyInfoList.size(); i++) {
			HSSFRow gridRow = sheet.createRow(1+i);
//			gridRow.setRowStyle(gridStyle);
			 // 合同流水号、
			gridRow.createCell(0).setCellValue(applyInfoList.get(i).getSerialNum());
			 // 申请人手机号、
			gridRow.createCell(1).setCellValue(applyInfoList.get(i).getApplyMobile());
			 // 个人/公司名称、
			gridRow.createCell(2).setCellValue(applyInfoList.get(i).getCustomerName());
			 // 个人/公司地址、
			gridRow.createCell(3).setCellValue(applyInfoList.get(i).getCustomerAddr());
			 // 联系人、
			gridRow.createCell(4).setCellValue(applyInfoList.get(i).getApplyUserName());
			 // 申请状态、
			gridRow.createCell(5).setCellValue(applyInfoList.get(i).getStatus());
			 // 申请时间、
			gridRow.createCell(6).setCellValue(applyInfoList.get(i).getApplyTm());
			 // 生效日期、
			gridRow.createCell(7).setCellValue(applyInfoList.get(i).getTakeEffectTM());
			 // 月结账号、
			gridRow.createCell(8).setCellValue(applyInfoList.get(i).getCardNo());
			 // 开发人员工号、
			gridRow.createCell(9).setCellValue(applyInfoList.get(i).getDevEmpNum());
			 // 网络代码、
			gridRow.createCell(10).setCellValue(applyInfoList.get(i).getNetCode());
			 // 快递决策人手机、
			gridRow.createCell(11).setCellValue(applyInfoList.get(i).getDecMakerMobile());
			 // 快递决策人电话、
			gridRow.createCell(12).setCellValue(applyInfoList.get(i).getDecMakerTelePhone());
			 // 主要寄件人手机
			gridRow.createCell(13).setCellValue(applyInfoList.get(i).getMostConsignorMobile());
		}
		book.write(response.getOutputStream());
		//清理session中的参数
		//这里暂时不清理,因为360浏览器请求了两次当前网关,导致下载失败!(第一次请求时正常,第二次请求时session中的参数已经被清空了,故会报错!)
//		request.getSession().removeAttribute(DOWNLOADPARAMSKEY);
	
 
 
	/**
	 * 列标题样式
	 * 
	 * @param wb
	 * @return
	 */
	private CellStyle getTitleStyle(HSSFWorkbook wb) {
		CellStyle style = wb.createCellStyle();
		style.setFont(getFont(wb));
		style.setAlignment(CellStyle.ALIGN_CENTER);
		style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
		style.setFillPattern(CellStyle.SOLID_FOREGROUND);
		style.setBorderBottom((short) 1);
		style.setBorderLeft((short) 1);
		style.setBorderRight((short) 1);
		style.setBorderTop((short) 1);
		style.setBottomBorderColor(HSSFColor.BLACK.index);
		return style;
	}

	/**
	 * 字体样式
	 * 
	 * @param wb
	 * @return
	 */
	private HSSFFont getFont(HSSFWorkbook wb) {
		HSSFFont font = wb.createFont();
		font.setFontName("Arial");
		font.setFontHeightInPoints((short) 10);
		return font;
	}


 

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值