日期:2014-05-17 浏览次数:20502 次
<html> <head> <script type="text/javascript"> function write_to_excel() { str=""; var mytable = document.getElementsByTagName("table")[0]; var ExcelApp = new ActiveXObject("Excel.Application"); var ExcelSheet = new ActiveXObject("Excel.Sheet"); ExcelSheet.Application.Visible = true; for(var i=0; i < mytable.rows.length; i++) { for(var j=0; j < mytable.rows[i].cells.length; j++) { ExcelSheet.ActiveSheet.Cells(i+1,j+1).Value = mytable.rows[i].cells[j].innerHTML; } } } </script></script></head> <body> <input type="submit" value="Export to EXCEL" onclick="write_to_excel();"/> <table><tr><td>First</td><td>second</td></tr><tr><td>2222</td><td>223333</td></tr></table> </body> </html>