转载在文章的方法下载下来的文件不能起名字和没有后缀;
解决方法:
tableToExcel: (function() {
var uri = "data:application/vnd.ms-excel;base64,",
template =
'<html><head><meta charset="UTF-8"></head><body><table>{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];
});
};
return function(table, name) {
var ctx = {
worksheet: name || "Worksheet",
table
};
// 关键是在html里创建一个a标签,然后写入一些信息,点击下载就行了
const _a = document.getElementById("downExcel")
_a.href = uri + base64(format(template, ctx));
_a.download = "商家列表.xls";
_a.innerText = "点击下载";
};
})()