Js export table data to excel is exported to excel document method



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>WEB Page export as EXCEL Method of documentation </title>
</head>
<body>
<table id="tableExcel" width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="5" align="center">
WEB Page export as EXCEL Method of documentation
</td>
</tr>
<tr>
<td>
 Column headings 1
</td>
<td>
 Column headings 2
</td>
<td>
 Column headings 3
</td>
<td>
 Column headings 4
</td>
<td>
 Column headings 5
</td>
</tr>
<tr>
<td>
aaa
</td>
<td>

</td>
<td>
ccc
</td>
<td>
ddd
</td>
<td>
eee
</td>
</tr>
<tr>
<td>
AAA
</td>
<td>

</td>
<td>
CCC
</td>
<td>
DDD
</td>
<td>
EEE
</td>
</tr>
<tr>
<td>
FFF
</td>
<td>
GGG
</td>
<td>
HHH
</td>
<td>
III
</td>
<td>
JJJ
</td>
</tr>
</table>
<input type="button" onclick="javascript:method1('tableExcel');" value=" The first method is imported into EXCEL">

<script language="javascript">

function method1(tableid) {//Copy the entire table to EXCEL

var curTbl = document.getElementById(tableid);

var oXL = new ActiveXObject("Excel.Application"); //Create the AX object excel

var oWB = oXL.Workbooks.Add(); //Gets the workbook object

var oSheet = oWB.ActiveSheet; //Activate the current sheet

var sel = document.body.createTextRange();

sel.moveToElementText(curTbl); //Move the contents of the table to TextRange

sel.select(); //Select everything in TextRange

sel.execCommand("Copy"); //Copy from TextRange

oSheet.Paste(); //Paste into the EXCEL of the activity

oXL.Visible = true; //Set the excel visibility properties

}


</script>

</body>
</html>