赞
踩
//第一种方法 function method1(tableid) { var curTbl = document.getElementById(tableid); var oXL = new ActiveXObject("Excel.Application"); var oWB = oXL.Workbooks.Add(); var oSheet = oWB.ActiveSheet; var sel = document.body.createTextRange(); sel.moveToElementText(curTbl); sel.select(); sel.execCommand("Copy"); oSheet.Paste(); oXL.Visible = true; }
//第二种方法 function method2(tableid) { var curTbl = document.getElementById(tableid); var oXL = new ActiveXObject("Excel.Application"); var oWB = oXL.Workbooks.Add(); var oSheet = oWB.ActiveSheet; var Lenr = curTbl.rows.length; for (i = 0; i < Lenr; i++) { var Lenc = curTbl.rows(i).cells.length; for (j = 0; j < Lenc; j++) { oSheet.Cells(i + 1, j + 1).value = curTbl.rows(i).cells(j).innerText; } } oXL.Visible = true; }
//第三种方法 function getXlsFromTbl(inTblId, inWindow) { try { var allStr = ""; var curStr = ""; if (inTblId != null && inTblId != "" && inTblId != "null") { curStr = getTblData(inTblId, inWindow); } if (curStr != null) { allStr += curStr; } else { alert("你要导出的表不存在"); return; } var fileName = getExcelFileName(); doFileExport(fileName, allStr); } catch (e) { alert("导出发生异常:" + e.name + "->" + e.description + "!"); } } function getTblData(inTbl, inWindow) { var rows = 0; var tblDocument = document; if (!!inWindow && inWindow != "") { if (!document.all(inWindow)) { return null; } else { tblDocument = eval(inWindow).document; } } var curTbl = tblDocument.getElementById(inTbl); var outStr = ""; if (curTbl != null) {
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。