POI导出,开发中经常会遇到数据导出这样的问题,…
2018-09-10 01:03:12来源:博客园 阅读 ()
@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语言中的异常处理
- 为什么阿里巴巴Java开发手册中不允许魔法值出现在代码中? 2020-06-09
- 「starter推荐」简单高效Excel 导出工具 2020-06-08
- 为什么阿里巴巴Java开发手册中强制要求接口返回值不允许使用 2020-06-06
- 是时候了解下软件开发的生命周期了! 2020-06-06
- Dubbo源码阅读-服务导出 2020-05-29
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash