IE browsers use JS to export Web pages to Excel and print

Source: Internet
Author: User
Tags html page

  briefly introduces a method that can use simple JS to export the information in the Web page to Excel and print, and you need a friend to refer to the following

In small projects that are not very high in requirements, you can implement these features with technologies that are not generic and are not new but can actually implement functionality well. This system is not shown to be complex and can be easily maintained.   Create a new exportprint.html page with the code shown below to enable you to export to Excel and print your Web pages.     Code as follows: <html>  <head>   <title>ie Browser use JS technology to export to Excel and print </title>   <style>    .table_stat {    border-right:0px;     border-bottom:0px;     Bo rder-left:1px solid #819BD8;     BORDER-TOP:1PX solid #819BD8;   &nbsp    .td_stat {    border-right:1px solid #819BD8;     BORDER-BOTTOM:1PX Solid #819BD8;   &NBSP}   </style>  </head>  <body>   <object classid= "CLSID : 8856f961-340a-11do-a96b-00c04fd705a2 "height=" 0 "id=" WebBrowser "width=" 0 "></object>   <table Width= "100%" align= "center" border= "0" cellpadding= "0" cellspacing= "0" style= "text-align:center;" class= "Table_stat" >    <tr>     <TD id= "title" align= "Center" nowrap= "NoWrap "class=" Td_stat "colspan=" 2 ">       user information     </td>    </tr> &nbsp ;  <tr>     <TD id= "title" align= "Center" nowrap= "nowrap" class= "Td_stat" colspan= "1" >   & nbsp   name     </td>     <TD id= "title" align= "Center" nowrap= "nowrap" class= "Td_stat" colspan = "1" >       John     </td>    </tr>      <tr>   & nbsp <TD id= "title" align= "Center" nowrap= "nowrap" class= "Td_stat" colspan= "2" >      <input type= " Button "id=" Export "value=" exports "onclick=" javascript:exporttoexcel (); ">      <input type=" button " id= "Print" value= "onclick=" Javascript:print (); ">     </td>    </tr>   </ table>  </body> </html>   <script type= "Text/javascript" >  //Export to Excel   function exportToExcel () {  IF (document.getElementById ("title")) {   try {    var orangeref = Document.body.createTextRange (); nbsp   Orangeref.execcommand ("Copy");     var appexcel = new ActiveXObject ("Excel.Application");     appexcel.visible = true;     APPEXCEL.WORKBOOKS.ADD (). Worksheets.item (1). Paste ();   &NBSP} catch (e) {    alert ("Error!") Maybe the browser or the amount of data is too big! ");     return;   &NBSP}    appexcel = null;    ORANGEREF = null;  } &nbsp    //printing  function print () {  if (document.getElementById ("title")) {   var Export = document.getElementById ("Export");    var print = document.getElementById ("print");    try {    Export.style.display = "none";     Print.style.display = "none";     Document.all.WebBrowser.ExecWB (6,1);   &NBSP} catch (e) {    alert ("Error!") Maybe the browser or the amount of data is too big! ");     return;    }    export.style.display = "";    print.style.display = "";  }  } </script>

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.