簡體   English   中英

如何使用Javascript從HTML表中導出Excel而沒有最后一行?

[英]how to export excel from Html table without last row using Javascript?

我可以從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);
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM