js导出excel的几种方式
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml">
4<head>
5 <meta http-equiv="Content-Type" content="text/html; charset=gb2312"/>
6 <title>WEB页面导出为EXCEL文档的方法</title>
7</head>
8<body>
9<table id="tableExcel" width="100%" border="1" cellspacing="0" cellpadding="0">
10 <tr>
11 <td colspan="5" align="center">WEB页面导出为EXCEL文档的方法</td>
12 </tr>
13 <tr>
14 <td>列标题1</td>
15 <td>列标题2</td>
16 <td>列标题3</td>
17 <td>列标题4</td>
18 <td>列标题5</td>
19 </tr>
20 <tr>
21 <td>aaa</td>
22 <td>bbb</td>
23 <td>ccc</td>
24 <td>ddd</td>
25 <td>eee</td>
26 </tr>
27 <tr>
28 <td>AAA</td>
29 <td>BBB</td>
30 <td>CCC</td>
31 <td>DDD</td>
32 <td>EEE</td>
33 </tr>
34 <tr>
35 <td>FFF</td>
36 <td>GGG</td>
37 <td>HHH</td>
38 <td>III</td>
39 <td>JJJ</td>
40 </tr>
41</table>
42<input type="button" onclick="javascript:method1('tableExcel');" value="第一种方法导入到EXCEL">
43<input type="button" onclick="javascript:method2('tableExcel');" value="第二种方法导入到EXCEL">
44<input type="button" onclick="javascript:getXlsFromTbl('tableExcel',null);" value="第三种方法导入到EXCEL">
45<SCRIPT LANGUAGE="javascript">
46function method1(tableid) {//整个表格拷贝到EXCEL中
47 var curTbl = document.getElementById(tableid);
48 var oXL = new ActiveXObject("Excel.Application");
49 //创建AX对象excel
50 var oWB = oXL.Workbooks.Add();
51 //获取workbook对象
52 var oSheet = oWB.ActiveSheet;
53 //激活当前sheet
54 var sel = document.body.createTextRange();
55 sel.moveToElementText(curTbl);
56 //把表格中的内容移到TextRange中
57 sel.select();
58 //全选TextRange中内容
59 sel.execCommand("Copy");
60 //复制TextRange中内容
61 oSheet.Paste();
62 //粘贴到活动的EXCEL中