Export HTML Table to Excel

View Code
<script Language="javascript">
function TableToExcel()
{
var strCopy = document.getElementById("MyTable").innerHTML;
window.clipboardData.setData("Text", strCopy);
var objExcel = new ActiveXObject ("Excel.Application");
objExcel.visible = true;

var objWorkbook = objExcel.Workbooks.Add;
var objWorksheet = objWorkbook.Worksheets(1);
objWorksheet.Paste;
}
</script
View Code
<HTML>
<HEAD>
<title>Export table to Excel in 10 lines</title>
</HEAD>
<BODY>
<href="javascript:RunScript()">Export to Excel</a><br/>
<span id=” MyTable”>
<table>
<tr><td style=”background-color:Gray;”>10 lines</td></tr>
<tr><td>This table was exported to Excel</td></tr>
</table>
</span>
</BODY>
</HTML>
you should enable the “Initialize and script ActiveX controls not marked as safe” in the security options of IE.

posted on 2012-03-17 15:12  博览潇湘  阅读(415)  评论(0编辑  收藏  举报

导航