≡
  • 网络编程
  • 数据库
  • CMS技巧
  • 软件编程
  • PHP笔记
  • JavaScript
  • MySQL
位置:首页 > 网络编程 > vue.js

vue+springmvc导出excel数据的实现代码

人气:612 时间:2019-04-11

这篇文章主要为大家详细介绍了vue+springmvc导出excel数据的实现代码,具有一定的参考价值,可以用来参考一下。

感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!

 

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数据的实现代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对四海网网站的支持!

本文来自:http://www.q1010.com/184/5324-0.html

注:关于vue+springmvc导出excel数据的实现代码的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。

关键词:vue.js

您可能感兴趣的文章

  • vue awesome swiper异步加载数据出现的bug问题
  • 分析Vue SPA项目优化小记
  • Vue实现todolist删除功能
  • 分析关于vue-area-linkage走过的坑
  • vue-router 源码实现前端路由的两种方式
  • vue 设置路由的登录权限的方法
  • 分析vue-cli中模拟数据的两种方法
  • Vue使用vue-area-linkage实现地址三级联动效果的示例
  • Vue引入sass并配置全局变量的方法
  • 使用vue-router完成简单导航功能【推荐】
上一篇:浅谈vue首屏加载优化
下一篇:分析关于vue-area-linkage走过的坑
热门文章
  • Vue 报错TypeError: this.$set is not a function 的解决方法
  • vue实现动态添加数据滚动条自动滚动到底部的示例代码
  • vue项目设置scrollTop不起作用(总结)
  • vue项目中使用vue-i18n报错的解决方法
  • iview实现select tree树形下拉框的示例代码
  • 分析关于element级联选择器数据回显问题
  • vue项目打包后打开页面空白解决办法
  • 解决element ui select下拉框不回显数据问题的解决
  • element-ui table span-method(行合并)的实现代码
  • element-ui 设置菜单栏展开的方法
  • 最新文章
    • 理解vue ssr原理并自己搭建简单的ssr框架
    • vue favicon设置以及动态修改favicon的方法
    • vue-router启用history模式下的开发及非根目录部署方法
    • 从零开始在NPM上发布一个Vue组件的方法步骤
    • Element input树型下拉框的实现代码
    • Vue 报错TypeError: this.$set is not a function 的解决方法
    • Vue.js组件高级特性实例分析
    • 浅谈VueJS SSR 后端绘制内存泄漏的相关解决经验
    • 分析Vue.js自定义tipOnce指令用法实例
    • 浅谈vuex actions和mutation的异曲同工

四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。