標籤:des style blog http color os
IE設定:
工具-> Internet選項-> 安全->自訂層級-> 對沒有標記安全層級的ActiveX控制項進行初始化
設為啟用!
1.匯出word
//指定地區匯出到Wordfunction html2word(Area) { var oWD = new ActiveXObject("Word.Application"); var oDC = oWD.Documents.Add("", 0, 1); var oRange = oDC.Range(0, 1); var sel = document.body.createTextRange(); sel.moveToElementText(document.getElementById(Area)); sel.select(); sel.execCommand("Copy"); oRange.Paste(); oWD.Application.Visible = true;}
Area:要匯出的html元素ID。
2.匯出Excel
//指定地區匯出到Excelfunction html2Excel(Area) { try { var oRangeRef = document.body.createTextRange(); oRangeRef.moveToElementText(document.getElementById(Area)); //oRangeRef.select(); oRangeRef.execCommand("Copy"); var oXL = new ActiveXObject("Excel.Application"); var oWB = oXL.Workbooks.Add; var oSheet = oWB.ActiveSheet; oSheet.Paste(); oXL.Visible = true; oSheet = null; oWB = null; oXL = null; } catch (e) { alert(e.description) }}
Area:要匯出的html元素ID。
轉載:http://www.cnblogs.com/sobne/articles/2103999.html