因为项目需要,所以在网上找了这些代码
<html> <body> <table width="100%" border="1" id = "PrintA"> <tr> <td>dfsdfds</td> <td>&dsfds</td> <td>&sdf;</td> <td>dsf</td> </tr> <tr> <td>dsf</td> <td>dsfds</td> <td>fsdfdsfdsf</td> <td>dsfs</td> </tr> <tr> <td>dsfds</td> <td>dsf</td> <td>dsfd</td> <td>sfds</td> </tr> <tr> <td> </td> <td>sdf</td> <td>fdsf</td> <td> </td> </tr> </table> <input type="button" onclick="javascript:AllAreaWord();" value="导出页面指定区域内容到Word"> <input type="button" onclick="javascript:AllAreaExcel();" value="导出页面指定区域内容到Excel"> <input type="button" onclick="javascript:CellAreaExcel();" value="导出表单单元格内容到Excel"> <SCRIPT LANGUAGE="javascript"> //指定页面区域内容导入Excel function AllAreaExcel() { var oXL = new ActiveXObject("Excel.Application"); var oWB = oXL.Workbooks.Add(); var oSheet = oWB.ActiveSheet; var sel=document.body.createTextRange(); sel.moveToElementText(PrintA); sel.select(); sel.execCommand("Copy"); oSheet.Paste(); oXL.Visible = true; } //指定页面区域“单元格”内容导入Excel function CellAreaExcel() { var oXL = new ActiveXObject("Excel.Application"); var oWB = oXL.Workbooks.Add(); var oSheet = oWB.ActiveSheet; var Lenr = PrintA.rows.length; for (i=0;i<Lenr;i++) { var Lenc = PrintA.rows(i).cells.length; for (j=0;j<Lenc;j++) { oSheet.Cells(i+1,j+1).value = PrintA.rows(i).cells(j).innerText; } } oXL.Visible = true; } //指定页面区域内容导入Word function AllAreaWord() { 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(PrintA); sel.select(); sel.execCommand("Copy"); oRange.Paste(); oWD.Application.Visible = true; //window.close(); oWD.ActiveWindow.ActivePane.View.Type=3 oWD.Application.close; } </SCRIPT> </body></html>
?
利有表格ID进行导出保存。
问题:
?? 当运行时,网页上会报页面错误,调式时会碰到??? automation服务器不能创建对象。
以下解决方法,本人用第二种方法解决了本次错误,以下全部可能尝试解决方法
echo 正在修复,这个过程可能需要几分钟,请稍候…… rundll32.exe advpack.dll /DelNodeRunDLL32 %systemroot%/System32/dacui.dll rundll32.exe advpack.dll /DelNodeRunDLL32 %systemroot%/Catroot/icatalog.mdb regsvr32 /s comcat.dll regsvr32 /s asctrls.ocx regsvr32 /s oleaut32.dll regsvr32 /s shdocvw.dll /I regsvr32 /s shdocvw.dll regsvr32 /s browseui.dll regsvr32 /s browseui.dll /I regsvr32 /s msrating.dll regsvr32 /s mlang.dll regsvr32 /s hlink.dll regsvr32 /s mshtml.dll regsvr32 /s mshtmled.dll regsvr32 /s urlmon.dll regsvr32 /s plugin.ocx regsvr32 /s sendmail.dll regsvr32 /s mshtml.dll /i regsvr32 /s scrobj.dll regsvr32 /s corpol.dll regsvr32 /s jscript.dll regsvr32 /s msxml.dll regsvr32 /s imgutil.dll regsvr32 /s cryptext.dll regsvr32 /s inseng.dll regsvr32 /s iesetup.dll /i regsvr32 /s cryptdlg.dll regsvr32 /s actxprxy.dll regsvr32 /s dispex.dll regsvr32 /s occache.dll regsvr32 /s iepeers.dll regsvr32 /s urlmon.dll /i regsvr32 /s cdfview.dll regsvr32 /s webcheck.dll regsvr32 /s mobsync.dll regsvr32 /s pngfilt.dll regsvr32 /s licmgr10.dll regsvr32 /s hhctrl.ocx regsvr32 /s inetcfg.dll regsvr32 /s trialoc.dll regsvr32 /s tdc.ocx regsvr32 /s MSR2C.DLL regsvr32 /s msident.dll regsvr32 /s msieftp.dll regsvr32 /s xmsconf.ocx regsvr32 /s ils.dll regsvr32 /s msoeacct.dll regsvr32 /s wab32.dll regsvr32 /s wabimp.dll regsvr32 /s wabfind.dll regsvr32 /s oemiglib.dll regsvr32 /s directdb.dll regsvr32 /s inetcomm.dll regsvr32 /s msoe.dll regsvr32 /s oeimport.dll regsvr32 /s msdxm.ocx regsvr32 /s dxmasf.dll regsvr32 /s laprxy.dll regsvr32 /s l3codecx.ax regsvr32 /s acelpdec.ax regsvr32 /s mpg4ds32.ax regsvr32 /s danim.dll regsvr32 /s Daxctle.ocx regsvr32 /s lmrt.dll regsvr32 /s datime.dll regsvr32 /s dxtrans.dll regsvr32 /s dxtmsft.dll regsvr32 /s wshom.ocx regsvr32 /s wshext.dll regsvr32 /s vbscript.dll regsvr32 /s scrrun.dll mstinit.exe /setup regsvr32 /s msnsspc.dll /SspcCreateSspiReg regsvr32 /s msapsspc.dll /SspcCreateSspiReg echo. echo. echo 修复成功!任意键退出! pause>nul
?