<html XMLns="http://www.w3.org/1999/xHTML" >
<head>
<title>标题页 </tITle>
<SCRIPT LANGUAGE="JAVAScript">
function ExportExcel()
{
var oXL = new ActiveXObject("Excel.Application"); //创建excel应用程序对象
var oWB = oXL.Workbooks.Add(); //创建工作簿
var oSheet = oWB.ActiveSheet; //获取当前活动的工作簿
var table = document.all.data; //获取当前页面中的表格
var hang = table.rows.length; //获取表格有多少行
var lie = table.rows(0).cells.length; //获取首行有多少列-多少标题
for (i=0;i <hang;i++) //添加标题到表格中
{
for (j=0;j <lie;j++)
{
oSheet.Cells(i+1,j+1).Value = table.rows(i).cells(j).innerText;//设置标题的内容
oSheet.Cells(i+1,j+1).NumberFormatLocal = "#";
}
}
oXL.Visible = true; //设置Excel的属性
oXL.UserControl = true;
}
</SCRIPT>
</head>
<body>
<input type="button" name="btnExcel" onclick="ExportExcel()" value="导出到excel" class="notPrint">
<table id="data" width="200" border="1">
<tr>
<td>姓名 </td>
<td>年龄 </td>
</tr>
<tr>
<td>张三 </td>
<td>22 </td>
</tr>
<tr>
<td>昂立 </td>
<td>888888888888 </td>
</tr>
<tr>
<td>效力 </td>
<td>23 </td>
</tr>
</table>
</body>
</HTML>