Generate JavaScript code for Word and Excel by copying table

Source: Internet
Author: User

  Create Word and Excel by copying a table, and it's a practical thing to feel this way, and here's a good example to help you.

The code is as follows: <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  <html xmlns=" http://www.w3.org/1999/xhtml ">  <head>  <meta http-equiv=" Content-type "content=" text/html; charset=gb2312 "/>  <title> Untitled document </title>  <script language=" JavaScript >  function automatewordautopaging (prefixion,count)   {  var OWD = new ActiveXObject ("Word.Application");  var ODC = oWD.Documents.Add ();  odc.showgrammaticalerrors = false; Shielding grammar check   odc.showspellingerrors = false; Screen spell checker   var oRange =odc.range (0,1);    for (i=0;i<count;i++)   {  var sel = document.body.cr Eatetextrange ();  var tablename = prefixion+i;  var Table = document.getElementById (tablename)   Sel.movetoelementtext (Table);  sel.select ();  sel.execcommand ("Copy");  oWD.Selection.Paste ();   OWD.Selection.InsertBreak (); Insert PointsPage characters  } //owd.activedocument.activewindow.view.type=3//Set browse mode   owd.visible = true; };    function Automateexcel (prefixion)   {  var eltable = document.getElementById ("Automateexcel");  var orangeref = Document.body.createTextRange ();  orangeref.movetoelementtext (eltable);  Orangeref.execcommand ("Copy");  try{  var appexcel = new ActiveXObject ("Excel.Application"); }catch (E   {  alert ("Cannot call Office objects, make sure your machine has Office installed and added the site name of this system to the list of trusted sites for IE!") ");  return; }  appexcel.visible = true;  appExcel.Workbooks.Add (). Worksheets.item (1). Paste ();  appexcel.workbooks (1). Worksheets.item (1). Columns ("A:a"). ColumnWidth = 100; //appexcel.workbooks (1). Worksheets.item (1). Columns ("B:b"). ColumnWidth = 21;  Appexcel = null };  </script>  </head>  <body>  < The input type= button "value=" is exported to Word automatic paging "onclick=" automatewordautopaging (' Table ', 5)/>  <input type= "button" value= "Export to Excel Control column width" onclick= "automateexcel (' Table ')"/>    <div id= " Automateexcel ">  <table class=tabp id=" Table0 "cellspacing=0 cellpadding=2 width=" 100% "align=center border =1>  <TR>  <td width= "100%" align= "center" > title 0</td>  </TR>  <tr >  <td align= "center" > Content 0</td>  </TR>  </TABLE>  <BR>  <table class=tabp id= "Table1" cellspacing=0 cellpadding=2-width= "100%" Align=center border=1>  nbsp <TD width= "100%" align= "center" > title 1</td>  </TR>  <TR>  <td align= "center" > Content 1</td>  </TR>  </TABLE>  <BR/>  <table class=tabp id= "Table2" cellspacing=0 cellpadding=2 width= "100%" Align=center border=1>  <TR>  <td width= "100%" Center "> Title 2</td>  </TR>  <TR>  <td align= "Center" > Content 2</td>  </TR>  </TABLE>  <BR/>  <table CLASS=TABP Id= "Table3" cellspacing=0 cellpadding=2 width= "100%" Align=center border=1>  <TR>  <td width= " 100% "align=" center "> title 3</td>  </TR>  <TR>  <td align=" center "> Content 3</td >  </TR>  </TABLE>  <BR/>  <table class=tabp id= "Table4" cellspacing=0 cellpadding=2 width= "100%" Align=center border=1>  <TR>  <td width= "100%" align= "Center" > Title 4 </TD>  </TR>  <TR>  <td align= "center" > Content 4</td>  </TR>   </TABLE>  <BR/>  </div>    </body>  </html> 
Related Article

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.