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

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 15:33: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數據的實現代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對錯新站長站網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 杂多县| 安义县| 泽库县| 翼城县| 兴和县| 葫芦岛市| 阜康市| 东山县| 汉阴县| 南丰县| 鹤山市| 澄迈县| 彭山县| 云和县| 望都县| 通许县| 历史| 福泉市| 辽源市| 武胜县| 寿宁县| 开阳县| 元氏县| 抚远县| 宁德市| 金阳县| 额敏县| 和平区| 芜湖市| 灌云县| 井冈山市| 内黄县| 满城县| 大荔县| 无棣县| 天津市| 本溪| 介休市| 襄汾县| 竹北市| 绥滨县|