{ console.info(typeof data) var a = document.cre..."/>
您好,登錄后才能下訂單哦!
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 = '用戶統(tǒng)計(jì)信息.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[] = {"用戶賬號(hào)", "充值總金額", "邀請總?cè)藬?shù)", "社群組"};//列名 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;
總結(jié)
以上所述是小編給大家介紹的vue+springmvc導(dǎo)出excel數(shù)據(jù)的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)億速云網(wǎng)站的支持!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。