js导出excell表

exportData(tableid, name) {
    console.log('导出')      let table;
      let uri = 'data:application/vnd.ms-excel;base64,',
        template = '<html><head><meta charset="UTF-8"></head><body><table  border="1">{table}</table></body></html>',
        base64 = function (s) {
          return window.btoa(unescape(encodeURIComponent(s)))
        },
        format = function (s, c) {
          return s.replace(/{(w+)}/g, function (m, p) {
            return c[p];
          })
        };
      table = document.getElementById(tableid)
      let ctx = {
        worksheet: name || 'Worksheet',
        table: table.innerHTML
      };
      window.location.href = uri + base64(format(template, ctx))
    },

  这个导出只适用于单页面的导出,真正表格打出都是后端写接口,前端调接口就可以了

原文地址:https://www.cnblogs.com/gitwusong/p/11492059.html