当用户点击“导出”按钮时,我需要将页面中的html表导出到Excel。现在,我在Firefox中找到了一个解决方案。
现在,它不会处理像ö,ü,ö这样常用的特殊字符,我们在这里使用的语言很常见,所以我想询问是否有人知道如何成功导出它们,没有问题?
这是我的代码:
function tabletoExcel(table,name) {
var uri = 'data:application/vnd.ms-excel;base64,',template = '
',base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))); },format = function (s,c) { return s.replace(/{(\w+)}/g,function (m,p) { return c[p]; }); };if (!table.nodeType) table = document.getElementById(table);
var ctx = { worksheet: name || 'Worksheet',table: table.innerHTML };
window.location.href = uri + base64(format(template,ctx));
}