vue+springmvc導(dǎo)出excel數(shù)據(jù)的實(shí)現(xiàn)代碼
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 = '用戶(hù)統(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ù)賬號(hào)", "充值總金額", "邀請(qǐng)總?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ì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- vue.js中導(dǎo)出Excel表格的案例分析
- Vue+axios+WebApi+NPOI導(dǎo)出Excel文件實(shí)例方法
- 詳解如何在Vue項(xiàng)目中導(dǎo)出Excel
- Vue結(jié)合后臺(tái)導(dǎo)入導(dǎo)出Excel問(wèn)題詳解
- vue中導(dǎo)出Excel表格的實(shí)現(xiàn)代碼
- Vue實(shí)現(xiàn)導(dǎo)出excel表格功能
- vue2.0 + element UI 中 el-table 數(shù)據(jù)導(dǎo)出Excel的方法
- Vue導(dǎo)出json數(shù)據(jù)到Excel電子表格的示例
- Vue2.0實(shí)現(xiàn)將頁(yè)面中表格數(shù)據(jù)導(dǎo)出excel的實(shí)例
- vue+element表格導(dǎo)出為Excel文件
相關(guān)文章
Vue項(xiàng)目中最新用到的一些實(shí)用小技巧
這篇文章主要給大家介紹了關(guān)于Vue項(xiàng)目中最新用到的一些實(shí)用小技巧,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11一個(gè)基于vue3+ts+vite項(xiàng)目搭建初探
當(dāng)市面上主流的組件庫(kù)不能滿(mǎn)足我們業(yè)務(wù)需求的時(shí)候,那么我們就有必要開(kāi)發(fā)一套屬于自己團(tuán)隊(duì)的組件庫(kù),下面這篇文章主要給大家介紹了一個(gè)基于vue3+ts+vite項(xiàng)目搭建的相關(guān)資料,需要的朋友可以參考下2022-05-05element-ui 插槽自定義樣式居中效果實(shí)現(xiàn)思路
這篇文章主要介紹了element-ui 插槽自定義樣式居中效果,簡(jiǎn)單來(lái)講實(shí)現(xiàn)思路是通過(guò)template標(biāo)簽可理解為一個(gè)內(nèi)嵌組件,寬高重新定義,可在自定義內(nèi)容外層套一層盒子,讓盒子占滿(mǎn)所有空間,再使用flex讓內(nèi)部元素居中,需要的朋友可以參考下2024-07-07Nuxt.js結(jié)合Serverless構(gòu)建無(wú)服務(wù)器應(yīng)用
Nuxt.js是一個(gè)基于Vue.js的框架,結(jié)合Serverless架構(gòu),Nuxt.js可以讓你構(gòu)建高度可擴(kuò)展、成本效益高的無(wú)服務(wù)器應(yīng)用,具有一定的參考價(jià)值,感興趣的可以了解一下2024-08-08使用vant-uploader上傳照片無(wú)法刪除的解決
這篇文章主要介紹了使用vant-uploader上傳照片無(wú)法刪除的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10npm install報(bào)錯(cuò)缺少python問(wèn)題及解決
這篇文章主要介紹了npm install報(bào)錯(cuò)缺少python問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06vue使用webSocket更新實(shí)時(shí)天氣的方法
本文將結(jié)合實(shí)例代碼,介紹vue使用webSocket更新實(shí)時(shí)天氣的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-06-06vite搭建vue2項(xiàng)目的實(shí)戰(zhàn)過(guò)程
自從體驗(yàn)了一下vite之后,真的太快了,然而對(duì)vue3還不是很熟練,就想著在vue2的項(xiàng)目中使用以下vite,下面這篇文章主要給大家介紹了關(guān)于vite搭建vue2項(xiàng)目的相關(guān)資料,需要的朋友可以參考下2022-11-11