1
2
3
4
5
导出表格6
7 varTmr;8 functiongetExplorer() {9 varexplorer=window.navigator.userAgent ;10 //ie
11 if(explorer.indexOf("MSIE")>= 0) {12 return 'ie';13 }14 //firefox
15 else if(explorer.indexOf("Firefox")>= 0) {16 return 'Firefox';17 }18 //Chrome
19 else if(explorer.indexOf("Chrome")>= 0){20 return 'Chrome';21 }22 //Opera
23 else if(explorer.indexOf("Opera")>= 0){24 return 'Opera';25 }26 //Safari
27 else if(explorer.indexOf("Safari")>= 0){28 return 'Safari';29 }30 }31 functionmethod(tableid) {32 if(getExplorer()=='ie')33 {34 varcurTbl=document.getElementById(tableid);35 varoXL= newActiveXObject("Excel.Application");36 varoWB=oXL.Workbooks.Add();37 varxlsheet=oWB.Worksheets(1);38 varsel=document.body.createTextRange();39 sel.moveToElementText(curTbl);40 sel.select();41 sel.execCommand("Copy");42 xlsheet.Paste();43 oXL.Visible= true;44
45 try{46 varfname=oXL.Application.GetSaveAsFilename("Excel.xls","Excel Spreadsheets (*.xls), *.xls");47 }catch(e) {48 print("Nested catch caught" +e);49 }finally{50 oWB.SaveAs(fname);51 oWB.Close(savechanges= false);52 oXL.Quit();53 oXL= null;54 Tmr=window.setInterval("Cleanup();",1);55 }56 }57 else
58 {59 tableToExcel(tableid)60 }61 }62 functionCleanup() {63 window.clearInterval(Tmr);64 CollectGarbage();65 }66 vartableToExcel=(function() {67 varuri= 'data:application/vnd.ms-excel;base64,',68 template= '
',69 base64= function(s) {returnwindow.btoa(unescape(encodeURIComponent(s))) },70 format= function(s, c) {71 returns.replace(/{(w+)}/g,72 function(m, p) {returnc[p]; }) }73 return function(table, name) {74 if(!table.nodeType) table=document.getElementById(table)75 varctx={worksheet: name|| 'Worksheet', table: table.innerHTML}76 window.location.href=uri+base64(format(template, ctx))77 }78 })()7980
81
82
83
84 导出Excel
85
86
87
88
89
90
91
92 金庸笔下人物
93
94
95
96
倚天屠龙记97
天龙八部98
鹿鼎记99
神雕侠侣100
射雕英雄传101
102
103
104
张无忌105
乔峰106
韦小宝107
杨过108
郭靖109
110
111
112
赵敏113
虚竹114
康熙115
小龙女116
黄蓉117
118
119
120
周芷若121
段誉122
鳌拜123
李莫愁124
杨康125
126
127
128