我可以从html表格导出excel。但是无法避免最后一行(tr),哪一行用于屏幕上的分页。所以这一行也显示在excel文件的结果中?
function DownloadToExcel(table){
debugger;
var t = document.getElementById(table);
t.border = 1;
var html = t.outerHTML;
html = encodeURIComponent(html);
var uri = 'data:application/vnd.ms-excel,' + html;
var downloadLink = document.createElement("a");
downloadLink.href = uri;
downloadLink.download = "sauberkeit.xlsx";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
最佳答案
只需在序列化 HTML 之前删除最后一行,然后再次将其添加回来。
var t = document.getElementById(table);
t.border = 1;
var last = t.lastElementChild;
t.removeChild(last);
var html = t.outerHTML;
t.appendChild(last);
...
关于javascript - 如何使用Javascript从Html表导出没有最后一行的Excel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49706188/