[英]how to export excel from Html table without last row using Javascript?
I can export excel from html table .but could not avoid last row (tr),which row is for pagination on screen.so this row also shows in result of excel file? 我可以从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);
}
Simply remove the last row before serialising the HTML, then add it back again. 只需在序列化HTML之前删除最后一行,然后再次将其添加回即可。
var t = document.getElementById(table);
t.border = 1;
var last = t.lastElementChild;
t.removeChild(last);
var html = t.outerHTML;
t.appendChild(last);
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.