标签:
非控件生成的页面需要导出时大家会怎么做导出呢??
下面提供两种html导出的功能
1.使用new ActiveXObject("Excel.Application")创建excel
function AutomateExcel(tablename) { var elTable = document.getElementById(tablename); //要导出的table id。 var oRangeRef = document.body.createTextRange(); oRangeRef.moveToElementText(elTable); oRangeRef.execCommand("Copy"); try { var appExcel = new ActiveXObject("Excel.Application"); var oWB = appExcel.Workbooks.Add(); //获取workbook对象 var oSheet = oWB.ActiveSheet; oSheet.Columns("1:5").ColumnWidth = 40 oWB.Worksheets.Item(1).Paste(); appExcel.Visible = true; //appExcel.ActiveSheet.Columns("1:5").ColumnWidth = 40 } catch (e) { alert("请查看浏览器ActiveX控件和插件是否启用!"); } finally { appExcel = null; } }
2.使用myzip导出
在<body>标签之外部署myzip对象
<OBJECT id="MyZipLib" CLASSID="CLSID:23676334-DBF4-4493-8F23-B15375FD923E" CODEBASE="/ActiveX/PBHelper/PBHelper.CAB#version=1,0,0,0" VIEWASTEXT> <PARAM NAME="_ExtentX" VALUE="159"> <PARAM NAME="_ExtentY" VALUE="159"> </OBJECT>
function AutomateExcel2(tableid) //读取表格中每个单元到EXCEL中 { //如果不存在记录,则无需进行导出Excel操作 var objTable = gridBar; if (objTable.rows.length < 3) return; var strHTML; strHTML = document.getElementById("MainTale").innerHTML; strHTML = "<meta http-equiv=‘Content-Type‘ content=‘text/html;charset=gb2312‘>" + strHTML; strHTML = strHTML.replace(/(<img\s+src=[\"|\‘][:|.|\/|_|\w]*[\"|\‘]\s*>)/gi, ""); strHTML = strHTML.replace(/\<input.*value=[\"|\‘]*([\S]*)[\‘|\"]*.*>[\s*\| ]*<\/td\>/gi, "$1</td>"); //debugger; MyZipLib.SaveToFile(strHTML); }
标签:
原文地址:http://www.cnblogs.com/KingUp/p/5741244.html