JS 将表格table导出excel

function tableToExcel(id)
{
    var tb = document.getElementById(id);
    var html = '<html><head><meta charset="UTF-8"></head><body><table>' + tb.innerHTML + '</table></body></html>';
    
    html = window.btoa(unescape(encodeURIComponent(html)));
    
    var uri = 'data:application/vnd.ms-excel;base64,' + html;
    window.location.href = uri;
}
原文地址:https://www.cnblogs.com/zjfree/p/6347461.html