This article describes the method of JavaScript to export web page content to Word and Excel. Share it for your reference. The specific implementation method is as follows:
<HTML><HEAD> <title>How to export WEB pages as EXCEL documents</title></HEAD><body><BR><table id = "PrintA" cellpacing="0" cellpadding="0" bgcolor = "#61FF13"><TR style="text-align : center;"><TD>Cell A</TD><TD>Cell A</TD><TD>Cell A</TD></TR><TR><TD colSpan=4 style="text-align : center;"><font color="BLUE" face="Verdana">Cell merge rows A</FONT></TD></TR></TABLE><BR><table id="PrintB" cellpacing="0" cellpadding="0"><TR style="text-align : center;"><TD>Cell B</TD><TD>Cell B</TD><TD>Cell B</TD></TR><TR><TD colSpan=4 style="text-align : center;">Cell merge rows B</TD></TR></TABLE><br><br><br><input type="button" onclick="javascript:AllAreaWord();" value="Export page specified area content to Word"><input type="button" onclick="javascript:AllAreaExcel();" value="Export page specified area content to Excel"><input type="button" onclick="javascript:CellAreaExcel();" value="Export form cell content to Excel"><SCRIPT LANGUAGE="javascript">//Import page area content to Excelfunction 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;}//Specify the page area "cell" content import Excelfunction 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; }//Import the content of the specified page area. Wordfunction 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();}</SCRIPT></body></html>I hope this article will be helpful to everyone's JavaScript programming.