多个HTML表格到Excel的转换

我想将HTML表格转换为工作表,同一页面上的多个表格应该转换成工作簿。

var htmltable= document.getElementById('table'); var html = htmltable.outerHTML; window.open('data:application/vnd.ms-excel,' + encodeURIComponent(html));' 

我已经试过这段代码将html表转换成excel文件,它对单表正常工作。 如果我有多个表,并希望从每个表创build多个工作表?

如果每个表都有一个唯一的id ,只需将该idreplace到第一行。 例如:

 <table name="mytable" id="mytable">...</table> <table name="urtable" id="urtable">...</table> 

JavaScript的

 var t1 = document.getElementById('mytable'); var xl1 = t1.outerHTML; window.open('data:application/vnd.ms-excel,' + encodeURIComponent(xl1)); var t2 = document.getElementById('urtable'); var xl2 = t2.outerHTML; window.open('data:application/vnd.ms-excel,' + encodeURIComponent(xl2));