欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

POI导出,开发中经常会遇到数据导出这样的问题,下面是我在开发中采用的解决方法,大家可以参考,具体的实现害的结合你自身的业务逻辑

程序员文章站 2022-08-11 18:47:18
@RequestMapping(value = "/drawPayFailExport",method = RequestMethod.GET,produces = "application/json")public ResponseData getAllDrawPayFailExport(Http ......

@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;

}