js 導出到word,excel
阿新 • • 發佈:2017-06-14
alert mat tab 選項 orange style class ora element
1>js導出,原理:復制頁面中的table,讓後粘貼到excle中
function exportToWord(id) { //Scripting.FileSystemObject (FSO 文本文件讀寫)被關閉了, //開啟FSO功能即可,在“運行”中執行regsvr32 scrrun.dll即可 try { var oElement = document.getElementById(id); var word = new ActiveXObject("Word.Application");var doc = word.Documents.Add("", 0, 1); //不打開模版直接加入內容 var Range = doc.Range(); var sel = document.body.createTextRange(); sel.moveToElementText(oElement); sel.select(); sel.execCommand("Copy"); Range.Paste(); word.Application.Visible= true; } catch (e) { alert("無法啟動Excel!\n\n" + e.message + "\n\n如果您確信您的電腦中已經安裝了Excel," + "那麽請調整IE的安全級別。\n\n具體操作:\n\n" + "工具 → Internet選項 → 安全 → 自定義級別 → 對沒有標記為安全的ActiveX進行初始化和腳本運行 → 啟用"); } }function exportToExcel(id) { //Scripting.FileSystemObject (FSO 文本文件讀寫)被關閉了, //開啟FSO功能即可,在“運行”中執行regsvr32 scrrun.dll即可 try { var oElement = document.getElementById(id); var oRangeRef = document.body.createTextRange(); oRangeRef.moveToElementText(oElement); oRangeRef.execCommand("Copy"); var oXL = new ActiveXObject("Excel.Application") var oWB = oXL.Workbooks.Add; var oSheet = oWB.ActiveSheet; oSheet.Paste(); oSheet.Cells.NumberFormatLocal = "@"; oXL.Selection.ColumnWidth = 8; oXL.Visible = true; oSheet = null; oWB = null; appExcel = null; } catch (e) { alert("無法啟動Excel!\n\n" + e.message + "\n\n如果您確信您的電腦中已經安裝了Excel," + "那麽請調整IE的安全級別。\n\n具體操作:\n\n" + "工具 → Internet選項 → 安全 → 自定義級別 → 對沒有標記為安全的ActiveX進行初始化和腳本運行 → 啟用"); }
js 導出到word,excel