使用POI导出EXCEL

/**
  * 填充导出信息
  * @param vo
  * @param inquiry
  * @param hetong
  */
 private void fixXunpanVO(XunpanVO vo,MagnetsInquiry inquiry,MagnetsHetong hetong,SysOperator operator){
  vo.setSerialNo(inquiry.getSerialNo());
  vo.setCreateTime(inquiry.getCreateTime());
  vo.setMaoyiType(inquiry.getLanguageType()==1?"内贸":"外贸");
  vo.setXunpanArea(inquiry.getLanguageType()==1?"中国":"国外");
  vo.setMoneyType(inquiry.getLanguageType()==1?"RMB":"USD");
  vo.setKehuNo(inquiry.getPromoter());
  vo.setProductType(inquiry.getProductType());
  vo.setPlateNumber(inquiry.getPlateNumber());
  vo.setNumber(inquiry.getNumber()+inquiry.getUnit());
  vo.setUserPrice((inquiry.getUserPrice()==null || "".equals(inquiry.getUserPrice()))?null:inquiry.getMoneyType()+inquiry.getUserPrice());
  vo.setShape(inquiry.getShape());
  vo.setSurfacing(inquiry.getSurfacing());
  vo.setMagnetizing(inquiry.getMagnetizing());
  if(inquiry.getPicture()!=null && !"".equals(inquiry.getPicture()) && inquiry.getPicture().lastIndexOf("pdf")!=-1){
   BufferedInputStream bis = FileUtil.getStreamByRemoteUrl("http://img3.ndfeb1688.com/"+inquiry.getPicture());
            byte[] buf=null;
   try {
    buf = new byte[bis.available()];
   } catch (IOException e) {
    e.printStackTrace();
   }
   vo.setPicture(buf);
  }else{
   vo.setPicture(null);
  }
  vo.setQuoteDate(inquiry.getQuoteDate());
  if(inquiry.getEndTime()==null || "".equals(inquiry.getEndTime())) vo.setEndTime(null);
  else vo.setEndTime(inquiry.getEndTime());
  vo.setSpec(inquiry.getSpec());
  vo.setContent(inquiry.getContent());
  vo.setEmkexPrice(inquiry.getEmkexPrice()==null?null:inquiry.getMoneyType()+inquiry.getEmkexPrice());
  vo.setWuliuPrice(null);
  vo.setWeight(null);
  vo.setPacked(null);
  vo.setShopRemark("无");
  vo.setRemark(inquiry.getRemark());
  vo.setXunpanStatus(getInquiryStatus(inquiry.getStatus(), inquiry.getFlogStatus()));
  vo.setXunpanPerson(inquiry.getPromoter());
  vo.setPhone(inquiry.getPromoterPhone());
  vo.setEmail(inquiry.getPromoterEmail());
  vo.setKefu(operator.getRealName());
  String shetherContract="否";
  if(hetong!=null) {
   shetherContract="是";
   vo.setHetongNo(hetong.getContractId());
  }
  vo.setWhetherContract(shetherContract);
  vo.setShopPrice(inquiry.getShopPrice());
  vo.setShopJiaoQi(null);
  vo.setLirun(null);
 }

/**
  * 询盘导出
  * @return
  */
 @Authority(modelUrl = "getInquiryList.do", childModel = "inquiryfenpei" , title = "分配")
 @RequestMapping("/exportXunpan.do")
 public void exportXunpan(String iids,Map<String,String> map , HttpServletResponse response){
  response.setContentType("octets/stream");
        response.addHeader("Content-Disposition",
                "attachment;filename=XP"+System.currentTimeMillis()+".xls");
        OutputStream out =null;
  try {
   List<XunpanVO> list=new ArrayList<XunpanVO>();
   XunpanVO vo=null;
   String[] iidAry=iids.split(",");
   if(iidAry.length<=0){
     return;
   }
   for(String iid:iidAry){
    MagnetsInquiry inquiry=inquiryService.getInquiryInfo(Integer.parseInt(iid));
    MagnetsHetong hetong=inquiryService.getMagnetsHetongByIid(inquiry.getId());
    SysOperator operator=inquiryService.getSysOperatorByUid(inquiry.getLocked());
    vo=new XunpanVO();
    fixXunpanVO(vo, inquiry, hetong ,operator);
    list.add(vo);
   }
   
    ExportExcel<XunpanVO> ex = new ExportExcel<XunpanVO>();
       String[] headers = {
         "询盘编号", "询盘日期", "贸易类型", "询盘地区", "货币",
         "客户编号", "产品类型", "产品牌号", "产品数量", "产品单价",
         "产品形状", "镀层", "充磁方向", "产品图纸", "最晚报价时间",
         "交期", "规格", "特殊要求", "亿迈克思报价", "物流费用",
         "单重", "包装", "供应商询盘备注", "备注说明", "询盘状态",
         "询盘人", "电话", "邮箱", "客服专员", "是否签合同",
         "合同编号", "供应商报价", "供应商交期", "利润"
       };
       out=response.getOutputStream();
          ex.exportExcel(headers, list, out);
          out.close();
          //responseAjax("ok", response);
  } catch (Exception e) {
   e.printStackTrace();
   logger.error(e.getMessage());
   //responseAjax("error", response);
  }
 }

你可能感兴趣的:(使用POI导出EXCEL)