JavaScript How to export Web page content to Word and Excel _javascript tips

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.