<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>网页表格导出到 EXCEL</title> </head> <body> <script language="javascript"> function saveas(Id) { var mStr; mStr = window.document.body.innerHTML ; var mWindow = window; window.document.body.innerHTML =Id.innerHTML; document.write(window.document.body.innerHTML); document.execCommand("saveas","1","报表.xls"); window.document.body.innerHTML = mStr; history.back(); } </script> 这个利用了剪贴板的功能,ID 可以定义为表格范围内的区域 最后调用这个函数: <input type="button" name="aa" onClick="saveas(AreaPrint)" values="报表下载"> <div id="AreaPrint"> <table id="table1" border="1"> <tr><td>第一个单元格</td><td>第二个单元格</td><td>第三个单元格</td> </tr> <tr><td>第四个单元格</td><td>第五个单元格</td><td>第六个单元格</td> </tr> </table> </div> </body> </html>
|