国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue+springmvc導出excel數據的實現代碼

2019-11-19 13:36:07
字體:
來源:轉載
供稿:網友

vue端處理

this.$http.get(this.service + '/user/excel',{responseType: 'blob'}).then(({data})=> {   console.info(typeof data)   var a = document.createElement('a');   var url = window.URL.createObjectURL(data);   a.href = url;   a.download = '用戶統計信息.xls';   a.click();   window.URL.revokeObjectURL(url);  })

web端處理

  int total=userBsService.getCount(null);  List<UserVo> list=userBsService.getList(null, 1, total);  String fileName = new Date().getTime() + "";   XSSFWorkbook wb=new XSSFWorkbook();   Sheet sheet=wb.createSheet();   Row row0=sheet.createRow(0);   String titleName[] = {"用戶賬號", "充值總金額", "邀請總人數", "社群組"};//列名   for(int i=0;i<titleName.length;i++){     sheet.setColumnWidth(i, 10 * 512);      row0.createCell(i).setCellValue(titleName[i]);   }   int i=0;   for(UserVo v:list){     Row row=sheet.createRow(i+1);     if(!StringUtils.isEmpty(v.getMobile())){        row.createCell(0).setCellValue(v.getMobile());      }else{        row.createCell(0).setCellValue(v.getEmail());      }     row.createCell(1).setCellValue(BigDecimalUtil.outputConvert(v.getAmount()));     row.createCell(2).setCellValue(v.getCounts());     row.createCell(3).setCellValue(v.getGroups());    i++;   }   ByteArrayOutputStream os = new ByteArrayOutputStream();  try{        try {      wb.write(os);      wb.close();     } catch (IOException e) {       e.printStackTrace();     }     byte[] content = os.toByteArray();     InputStream is = new ByteArrayInputStream(content);     response.reset();     response.setContentType("application/vnd.ms-excel;charset=utf-8");     response.setHeader("Content-Disposition", "attachment;filename="+ new String((fileName + ".xls").getBytes(), "iso-8859-1"));     ServletOutputStream out = response.getOutputStream();     BufferedInputStream bis = null;     BufferedOutputStream bos = null;     try {       bis = new BufferedInputStream(is);       bos = new BufferedOutputStream(out);       byte[] buff = new byte[2048];       int bytesRead;       while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {         bos.write(buff, 0, bytesRead);       }     } catch (final IOException e) {       throw e;     } finally {       if (bis != null)         bis.close();       if (bos != null)         bos.close();     }   }catch (Exception e){   }  return null;

總結

以上所述是小編給大家介紹的vue+springmvc導出excel數據的實現代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 荔浦县| 巴中市| 家居| 宣汉县| 营山县| 芒康县| 勐海县| 临颍县| 兴业县| 南岸区| 巩留县| 西畴县| 阿勒泰市| 沾化县| 浏阳市| 收藏| 威信县| 富顺县| 南宫市| 墨脱县| 威海市| 手游| 江陵县| 丰宁| 渑池县| 南江县| 雅安市| 江达县| 平定县| 濮阳县| 巨鹿县| 定南县| 全州县| 常德市| 日照市| 榕江县| 阿尔山市| 邛崃市| 中山市| 精河县| 松原市|