ExcelUtils.downloadExcel导出excel表

 log.info("---进入 FapiaoReportServiceImpl 类中 importExcel 方法!---");
        String taxName= CommonUtils.trim(request.getParameter("taxName"));
        String taxID = CommonUtils.trim(request.getParameter("taxID"));
        String goodsName = CommonUtils.trim(request.getParameter("goodsName"));
        String orderID = CommonUtils.trim(request.getParameter("orderID"));
        String contactNo = CommonUtils.trim(request.getParameter("contactNo"));
        String startTime = CommonUtils.trim(request.getParameter("startTime"));
        String endTime = CommonUtils.trim(request.getParameter("endTime"));

        List<Object[]> excelList=new ArrayList<Object[]>();
        List<FapiaoReport> fapiaoReportsList=fapiaoReportMapper.getList(taxName,taxID,goodsName,orderID,contactNo,startTime,endTime);//传出的实体集合
        log.info("fapiaoReportsList 出参:{}",JSON.toJSONString(fapiaoReportsList));
        String[] codeArray = {"FAPIAO_TYPE", "HEAD_TYPE"};//设置数据字典字段
        List<T_DATA_DIC> dataDics = dataDicMapper.getDataDicForMoreCode(codeArray);
        //遍历集合集合内判断每一个字段是否为空
        for (FapiaoReport fapiaoReport : fapiaoReportsList) {
            Object[] ob = {
                StringUtils.isEmpty(fapiaoReport.getOrderID()) ? "" :fapiaoReport.getOrderID() ,
                StringUtils.isEmpty(fapiaoReport.getContactNo()) ? "" :fapiaoReport.getContactNo() ,
                StringUtils.isEmpty(fapiaoReport.getGoodsName()) ? "" : fapiaoReport.getGoodsName() ,
                StringUtils.isEmpty(fapiaoReport.getFapiaoAmt() ) ? "" : fapiaoReport. getFapiaoAmt(),
                StringUtils.isEmpty(fapiaoReport.getFapiaoType()) ? "" : fapiaoReport. getFapiaoType(),
                StringUtils.isEmpty(fapiaoReport.getFapiaoTypeName()) ? "" : fapiaoReport. getFapiaoTypeName(),
                StringUtils.isEmpty(CommonTools.getData("FAPIAO_TYPE@"+fapiaoReport.getFapiaoType(),dataDics)) ? "" : CommonTools.getData("FAPIAO_TYPE@"+fapiaoReport.getFapiaoType(),dataDics),
                StringUtils.isEmpty(fapiaoReport.getCreateTime()) ? "" : fapiaoReport. getCreateTime(),
                StringUtils.isEmpty(fapiaoReport.getHeadType()) ? "" : fapiaoReport.getHeadType() ,
                StringUtils.isEmpty(fapiaoReport.getHeadTypeName()) ? "" : fapiaoReport.getHeadTypeName() ,
                StringUtils.isEmpty(CommonTools.getData("HEAD_TYPE@"+fapiaoReport.getHeadType(),dataDics)) ? "" : CommonTools.getData("HEAD_TYPE@"+fapiaoReport.getHeadType(),dataDics),
                StringUtils.isEmpty(fapiaoReport.getTaxName() ) ? "" : fapiaoReport.getTaxName() ,
                StringUtils.isEmpty(fapiaoReport.getTaxID() ) ? "" : fapiaoReport.getTaxID() ,
                StringUtils.isEmpty(fapiaoReport.getAddress()) ? "" : fapiaoReport.getAddress (),
                StringUtils.isEmpty(fapiaoReport.getPhone()) ? "" : fapiaoReport.getPhone() ,
                StringUtils.isEmpty(fapiaoReport.getOpenBankName()) ? "" : fapiaoReport.getOpenBankName() ,
                StringUtils.isEmpty(fapiaoReport.getOpenAccno()) ? "" : fapiaoReport.getOpenAccno() ,
            };

            excelList.add(ob);
        }
        //防止传空
        if ("".equals(CommonUtils.trim(excelList)) || excelList.size() == 0) {
            return RespCodeEnum.TRD_0007.toResponseBo();
        }

        log.info("excel导出:"+excelList);
        String fileName="发票信息报表";
        List<String> lists=new ArrayList<String>();
        lists.add("订单号");
        lists.add("合同号");
        lists.add("商品名称");
        lists.add("开票金额");
        lists.add("开票类型");
        lists.add("开票类型(名称)");
        lists.add("提交日期");
        lists.add("抬头类型");
        lists.add("抬头类型(名称)");
        lists.add("纳税人名称");
        lists.add("纳税人识别号");
        lists.add("开户地址");
        lists.add("开户电话");
        lists.add("开户银行");
        lists.add("开户账号");

       // LoginSysUser loginSysUser= (LoginSysUser) request.getSession().getAttribute(SESSION_SYS_USER);loginSysUser.getUserNo()
        //导出的字段名lists,response是方法的入参,excelList是实体集合,fileName表名,"aaa"是导
        //出表操作人的名字
        ExcelUtils.downloadExcel(lists,response,excelList,fileName,"aaa");
        log.info("---退出 FapiaoReportServiceImpl 类中 importExcel 方法!---");
        return null;
    }
import com.alibaba.druid.util.StringUtils;//对了要这个包

上一篇:文件通过后台判断获取,并转成base64格式返给前端(一)


下一篇:使用substring截取字符串,解决错误:Java.lang.StringIndexOutOfBoundsException:String index out of range: 5