<div class="codetitle"> <span><a style="CURSOR: pointer" data="87528" class="copybut" id="copybut87528" onclick="doCopy('code87528')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code87528"> <br><table id="PrintA" width="100%" border="1" cellspacing="0" cellpadding="0" bgcolor="#61FF13"> <br><tr style="text-align : center;"> <br><td>单元格A</td> <br><td>单元格A</td> <br><td>单元格A</td> <br><td>单元格A</td> <br> </tr> <br><tr> <br><td colspan="4" style="text-align : center;"><font color="BLUE" face="Verdana">单元格合并行A</font></td> <br> </tr> <br> </table> <br><table id="PrintB" width="100%" border="1" cellspacing="0" cellpadding="0"> <br><tr style="text-align : center;"> <br><td>单元格B</td> <br><td>单元格B</td> <br><td>单元格B</td> <br><td>单元格B</td> <br> </tr> <br><tr> <br><td colspan="4" style="text-align : center;">单元格合并行B</td> <br> </tr> <br> </table> <br><br> <br><input type="button" onclick="javascript:AllAreaWord();" value="导出页面指定区域内容到Word"> <br><input type="button" onclick="javascript:AllAreaExcel();" value="导出页面指定区域内容到Excel"> <br><input type="button" onclick="javascript:CellAreaExcel();" value="导出表单单元格内容到Excel"> <br><br><script language="javascript"> <BR>//指定页面区域内容导入Excel <BR>function AllAreaExcel() <BR>{ <BR>var oXL = new ActiveXObject("Excel.Application"); <BR>var oWB = oXL.Workbooks.Add(); <BR>var oSheet = oWB.ActiveSheet; <BR>var sel=document.body.createTextRange(); <BR>sel.moveToElementText(PrintA); <BR>sel.select(); <BR>sel.execCommand("Copy"); <BR>oSheet.Paste(); <BR>oXL.Visible = true; <BR>} <BR>//指定页面区域“单元格”内容导入Excel <BR>function CellAreaExcel() <BR>{ <BR>var oXL = new ActiveXObject("Excel.Application"); <BR>var oWB = oXL.Workbooks.Add(); <BR>var oSheet = oWB.ActiveSheet; <BR>var Lenr = PrintA.rows.length; <BR>for (i=0;i<Lenr;i++) <BR>{ <BR>var Lenc = PrintA.rows(i).cells.length; <BR>for (j=0;j<Lenc;j++) <BR>{ <BR>oSheet.Cells(i+1,j+1).value = PrintA.rows(i).cells(j).innerText; <BR>} <BR>} <BR>oXL.Visible = true; <BR>} <BR>//指定页面区域内容导入Word <BR>function AllAreaWord() <BR>{ <BR>var oWD = new ActiveXObject("Word.Application"); <BR>var oDC = oWD.Documents.Add("",0,1); <BR>var oRange =oDC.Range(0,1); <BR>var sel = document.body.createTextRange(); <BR>sel.moveToElementText(PrintA); <BR>sel.select(); <BR>sel.execCommand("Copy"); <BR>oRange.Paste(); <BR>oWD.Application.Visible = true; <BR>//window.close(); <BR>} <BR></script><br> </div>