zoukankan      html  css  js  c++  java
  • 如何不借助插件前端自己写导出excel --csv格式

    exportCsv(title, data, fileName){
            let today = new Date();
            let tadayDate = today.getFullYear() + "-" +(today.getMonth() + 1) + "-" + today.getDate();
            fileName = "学校报名列表-" + tadayDate;
            var CSV = '';
            var row = "";
     
            let temp = []
            data=this.appTable
     
            title=[
            {title:'名字1',field:'account_name'},
            {title:'名字2',field:'student_name'},
            {title:'名字3',field:'application_project'},
            {title:'子名字4',field:'application_events'},
            {title:'名字',field:'application_channel'},
            ]
            
            for (var i = 0; i < title.length; i++) {
              if(title[i].title){
                row += title[i].title + ',';
              }
            }
            row = row.slice(0, -1);
            CSV += row + ' ';
            
            for (var i = 0; i < data.length; i++) {
              var row = "";
              for (var j = 0; j < title.length; j++) {
              if(title[j].title){        
                 row += '"' + data[i][title[j].field] +'" ,';
              }
              }
              row.slice(0, row.length - 1);
              CSV += row + ' ';
            }
            
            if (CSV == '') {
              alert("Invalid data");
              return;
            }
            
            var fileName = fileName;
            var uri = new Blob(['ufeff' + CSV], {type:"text/csv"});
            
            if (window.navigator && window.navigator.msSaveOrOpenBlob) { // for IE
              window.navigator.msSaveOrOpenBlob(CSV, fileName + ".csv");
            } else { // for Non-IE(chrome、firefox etc.)
              var link = document.createElement("a");
              link.href = URL.createObjectURL(uri);
            
              link.style = "visibility:hidden";
              link.download = fileName + ".csv";
              document.body.appendChild(link);
              link.click();
              document.body.removeChild(link);
            }
            },

  • 相关阅读:
    SpringCloud微服务Zuul跨域问题
    com.netflix.zuul.exception.ZuulException: Hystrix Readed time out
    Java实现遍历N级树形目录结构
    ubuntu安装Nginx
    redis报错:java.net.SocketException: Broken pipe (Write failed); nested exception is redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Broken pipe (Write failed)
    Java设置接口跨域
    SpringBoot使用qq邮箱发送邮件
    linux使用Nginx搭建静态资源服务器
    Spring Boot 正常启动后访问Controller提示404
    分享2019年陆陆续续读过的书-附书单
  • 原文地址:https://www.cnblogs.com/gunelark/p/14069508.html
Copyright © 2011-2022 走看看