将Table 用JS导出成Excel function exportTablebyid(tableid) {tableToExcel(tableid);}/** 将div里面的table 导出成excel * */var tableToExcel = (function() {var uri = 'data:application/vnd.ms-excel;base64,';var template = ' {table} ';
function exportTablebyid(tableid) { tableToExcel(tableid); } /** 将div里面的table 导出成excel * */ var tableToExcel = (function() { var uri = 'data:application/vnd.ms-excel;base64,'; var template = ' {table} '; var base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }; var format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }) }; return function(table, name) { if (!table.nodeType) table = document.getElementById(table) table.style='border="1" style="border-color: black;"'; var ctx = { worksheet : name || 'Worksheet', table : table.innerHTML } window.location.href = uri + base64(format(template, ctx)) } })()