因为项目需要,所以在网上找了这些代码
<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服务器不能创建对象。
以下解决方法,本人用第二种方法解决了本次错误,以下全部可能尝试解决方法
- 如果是Scripting.FileSystemObject (FSO 文本文件读写)被关闭了,开启FSO功能即可,在“运行”中执行regsvr32 scrrun.dll即可
- 安全模式设置成“中”,如果javascript脚本中报这个错误,还应将IE的安全设置“不允许运行未标记为安全的activeX控件”启用即可。
- 注意如果您将相应的网站设成“受信任的站点”,必须对“受信任的站点”进行相应的IE安全设置,此时如果对“Internet”IE设置将是徒劳的。
- 有些脚本需要微软的 MSXML 控件才能进入。当使用 IE 5 以上版本的缺省安全模式时,会提示是否接受 MSXML 控件,如果接受,MSXML 将自动安装到您的机器上(得等上几分钟)。如果自动安装不成功,可以自行下载和安装 MSXML 3.0 SP7(附件中有下载)。有时是由于msxml 3服务被关掉了,使用regsvr32 msxml3.dll即可
- 用上面方法基本上能决问题。如果是在安装某个软件后出现这种问题,可尝度卸载该软件或重装一下!
- 如果还是不行,试试以下方法:
- 请将以下语句复制到记事本中,另存为后缀为.cmd的文件,并运行。当然在命令行下一句句运行也没问题。
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
?