其他分享
首页 > 其他分享> > ExcelUtils.downloadExcel导出excel表

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;//对了要这个包

标签:String,ExcelUtils,fapiaoReport,excel,lists,add,downloadExcel,isEmpty,StringUtils
来源: https://blog.csdn.net/l915652022/article/details/121414904