如何使用Javascript从Html表中导出excel,而不使用最后一行?
我可以从html表格中导出excel。但无法避免最后一行(tr),这一行在屏幕上用于分页。所以这一行也显示在excel文件的结果中如何使用Javascript从Html表中导出excel,而不使用最后一行?,javascript,jquery,Javascript,Jquery,我可以从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:a
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);
...
在序列化HTML之前,只需删除最后一行,然后再次添加
var t = document.getElementById(table);
t.border = 1;
var last = t.lastElementChild;
t.removeChild(last);
var html = t.outerHTML;
t.appendChild(last);
...
很抱歉迟了回复。您的逻辑是正确的。谢谢。我只是稍微改变了你的剧本。var lastRow=table.rows[table.rows.length-1];var rowCount=table.rows.length;表.deleteRow(rowCount-1);var html=table.outerHTML;表2.appendChild(最后一行)@GowthamAlan如果这解决了您的问题,请不要忘记单击投票箭头下的勾号,将此答案标记为“已接受”。我知道,但我是这里的新手,所以我应该有代表进行投票。一旦我得到了,我将投你的票。@GowthamAlan您不需要任何信誉点来接受答案。@GowthamAlan谢谢!:-)很抱歉迟了回复。您的逻辑是正确的。谢谢。我只是稍微改变了你的剧本。var lastRow=table.rows[table.rows.length-1];var rowCount=table.rows.length;表.deleteRow(rowCount-1);var html=table.outerHTML;表2.appendChild(最后一行)@GowthamAlan如果这解决了您的问题,请不要忘记单击投票箭头下的勾号,将此答案标记为“已接受”。我知道,但我是这里的新手,所以我应该有代表进行投票。一旦我得到了,我将投你的票。@GowthamAlan您不需要任何信誉点来接受答案。@GowthamAlan谢谢!:-)