日期:2014-05-16 浏览次数:20548 次
因为项目需要,所以在网上找了这些代码
<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 shdoc