POI导出,开发中经常会遇到数据导出这样的问题,…

2018-09-10 01:03:12来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

@RequestMapping(value = "/drawPayFailExport",method = RequestMethod.GET,produces = "application/json")
public ResponseData getAllDrawPayFailExport(HttpServletRequest request, HttpServletResponse response){
String startTime = null;
String endTime = null;
String userName = null;
String accountNumber = null;
if (!"undefined".equals(request.getParameter("startTime"))){
startTime = request.getParameter("startTime");
}
if (!"undefined".equals(request.getParameter("endTime"))){
endTime = request.getParameter("endTime");
}
if (StringUtils.isNotBlank(request.getParameter("userName"))){
userName = request.getParameter("userName");
}
if (StringUtils.isNotBlank(request.getParameter("accountNumber"))){
accountNumber = request.getParameter("accountNumber");
}
DrawPayFailDto drawPayFailDto = new DrawPayFailDto();
drawPayFailDto.setStartTime(startTime);
drawPayFailDto.setEndTime(endTime);
drawPayFailDto.setUserName(userName);
drawPayFailDto.setAccountNumber(accountNumber);
logger.info("兑换提现付款失败导出请求参数:"+JSON.toJSON(drawPayFailDto));
//第一步创建workbook
HSSFWorkbook wb = new HSSFWorkbook();

//第二步创建sheet
HSSFSheet sheet = wb.createSheet("兑换提现付款失败表");

//第三步创建行row:添加表头0行
HSSFRow row = sheet.createRow(0);
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); //居中

//第四步创建单元格
HSSFCell cell = row.createCell(0); //第一个单元格
cell.setCellValue("序号"); //设定值
cell.setCellStyle(style); //内容居中

cell = row.createCell(1); //第二个单元格
cell.setCellValue("申请编号");
cell.setCellStyle(style);

cell = row.createCell(2); //第三个单元格
cell.setCellValue("申请时间");
cell.setCellStyle(style);

cell = row.createCell(3); //第四个单元格
cell.setCellValue("用户姓名");
cell.setCellStyle(style);

cell = row.createCell(4); //第五个单元格
cell.setCellValue("手机号");
cell.setCellStyle(style);

cell = row.createCell(5); //第六个单元格
cell.setCellValue("实际应付金额");
cell.setCellStyle(style);

cell = row.createCell(6); //第七个单元格
cell.setCellValue("退款银行");
cell.setCellStyle(style);

cell = row.createCell(7); //第八个单元格
cell.setCellValue("银行卡号");

cell.setCellStyle(style);

 

cell = row.createCell(8);//第九个单元格

cell.setCellValue("初审人");

cell.setCellStyle(style);

 

cell = row.createCell(9); //第十个单元格

cell.setCellValue("复审人");

cell.setCellStyle(style);

 

cell = row.createCell(10); //第十一个单元格

cell.setCellValue("支付渠道");

cell.setCellStyle(style);

 

cell = row.createCell(11); //第十二个单元格

cell.setCellValue("付款状态");

cell.setCellStyle(style);

ResponseData responseData = refundTicketDrawService.selectDrawPayFailList(drawPayFailDto);

List<DrawConfirmDetailVo> list = null;

if ("0".equals(responseData.getStatus())){

  list = (List<DrawConfirmDetailVo>) responseData.getData();

}

if (list != null && list.size() > 0){

   for (int i = 0; i < list.size(); i++){

     DrawConfirmDetailVo drawConfirmDetailVo = list.get(i); //创建行

    row = sheet.createRow(i+1); //创建单元格并且添加数据

    row.createCell(0).setCellValue(i+1);

    row.createCell(1).setCellValue(drawConfirmDetailVo.getApplyNo());

    row.createCell(2).setCellValue(drawConfirmDetailVo.getApplytime());

    row.createCell(3).setCellValue(drawConfirmDetailVo.getRealName());

    row.createCell(4).setCellValue(drawConfirmDetailVo.getAccountNumber());

    row.createCell(5).setCellValue(String.valueOf(drawConfirmDetailVo.getActualMoney()));

    row.createCell(6).setCellValue(drawConfirmDetailVo.getBankName());

    row.createCell(7).setCellValue(drawConfirmDetailVo.getBankAccount());

    row.createCell(8).setCellValue(drawConfirmDetailVo.getFirstAuditPerson());

    row.createCell(9).setCellValue(drawConfirmDetailVo.getSecondAuditPerson());

    row.createCell(10).setCellValue(drawConfirmDetailVo.getPayChannel());

   if (drawConfirmDetailVo.getPayState() == 0){

     row.createCell(11).setCellValue(PayState.Pay_wait.getDesc());

   } else if (drawConfirmDetailVo.getPayState() == 1){

    row.createCell(11).setCellValue(PayState.Pay_success.getDesc());

   }else if (drawConfirmDetailVo.getPayState() == 2){

     row.createCell(11).setCellValue(PayState.Pay_fail.getDesc());

   }else if (drawConfirmDetailVo.getPayState() == 3){

    row.createCell(11).setCellValue(PayState.Pay_ing.getDesc());

}

}

}

  //web浏览通过MIME类型判断文件是excel类型

  response.setContentType("application/vnd.ms-excel;charset=utf-8");

  response.setCharacterEncoding("utf-8");

 

   //第六步将生成excel文件保存到指定路径下

   try { //FileOutputStream fout = new FileOutputStream("D:\\MediaPos.xls");

      String fileName = URLEncoder.encode("兑换提现付款失败表.xls");

     response.setHeader("Content-disposition", "attachment;filename=" + fileName);

     OutputStream fout = response.getOutputStream(); wb.write(fout); fout.close();

  } catch (IOException e) {

   logger.error("导出兑换提现付款失败表出错",e);

}

    return null;

}

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Java类加载过程

下一篇:Java语言中的异常处理