The example in this article describes how JavaScript exports Web page content to Word and Excel. Share to everyone for your reference. The implementation method is as follows:
<HTML> <HEAD> <title>web page Export to Excel document </title> </HEAD> <body> <BR> < Table id = "PrintA" width= "100%" border= "1" cellspacing= "0" cellpadding= "0" bgcolor = "#61FF13" > <tr style= "Text-al" Ign:center; " > <TD> cell a</td> <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 Row a</font> </TD> </TR> </TABLE> <BR> <table id= "Printb" width= "100%" border= "1" cellspacing= "0" cellpadding= "0" > <tr style= "text-align:center;" > <TD> cell b</td> <TD> cell b</td> <TD> cell b</td> <TD> cell b</td> </ tr> <TR> <td colspan=4 style= "Text-align:center;" > Cell merge Row b</td> </TR> </TABLE> <br><br><br> <input type= "button" onclick= "
Javascript:allareaword (); " Value= the Export page in the specified areaAllow word "> <input type=" button "onclick=" Javascript:allareaexcel ();
value= "Export page specify area content to Excel" > <input type= button "onclick=" Javascript:cellareaexcel (); " value= "Export table meta content to Excel" > <script language= "javascript" >//Specify page area content import Excel function Allareaexcel () {var oXL = n
EW 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;
//Specifies the page area cell content import 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; //Specify page area content import 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 (); } </SCRIPT> </body>
The
wants this article to help you with your JavaScript programming.