欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ie瀏覽器使用js導(dǎo)出網(wǎng)頁(yè)到excel并打印

 更新時(shí)間:2014年03月11日 09:26:35   作者:  
簡(jiǎn)單介紹一種可以使用簡(jiǎn)單的JS來(lái)實(shí)現(xiàn)把網(wǎng)頁(yè)中的信息原樣導(dǎo)出到Excel、還可以打印的方法,需要的朋友可以參考下

在一些要求不是很高的小項(xiàng)目中,可以使用一些雖不是通用且不是新技術(shù)但是確實(shí)可以很好實(shí)現(xiàn)功能的技術(shù)來(lái)實(shí)現(xiàn)這些功能。這樣系統(tǒng)不是顯示的很復(fù)雜,且可以方便維護(hù)。 
新建一個(gè)exportPrint.html頁(yè)面,里面的代碼如下所示,就可以實(shí)現(xiàn)導(dǎo)出到Excel和打印網(wǎng)頁(yè)。

復(fù)制代碼 代碼如下:

<html>
 <head>
  <title>IE瀏覽器使用JS技術(shù)導(dǎo)出到Excel和打印</title>
  <style>
   .table_stat {
    border-right:0px;
    border-bottom:0px;
    border-left:1px solid #819BD8;
    border-top:1px solid #819BD8;
   }
   .td_stat {
    border-right:1px solid #819BD8;
    border-bottom:1px solid #819BD8;
   }
  </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">
     用戶信息
    </td>
   </tr>
   <tr>
    <td id="title" align="center" nowrap="nowrap" class="td_stat" colspan="1">
     姓名
    </td>
    <td id="title" align="center" nowrap="nowrap" class="td_stat" colspan="1">
     張三
    </td>
   </tr>

   <tr>
    <td id="title" align="center" nowrap="nowrap" class="td_stat" colspan="2">
     <input type="button" id="export" value="導(dǎo)出" onclick="javascript:exportToExcel();" >
     <input type="button" id="print" value="打印" onclick="javascript:print();" >
    </td>
   </tr>
  </table>
 </body>
</html>

<script type="text/javaScript">
 //導(dǎo)出到Excel
 function exportToExcel() {
  if(document.getElementById("title")) {
   try {
    var oRangeRef = document.body.createTextRange();
    oRangeRef.execCommand("Copy");
    var appExcel = new ActiveXObject("Excel.Application");
    appExcel.visible = true;
    appExcel.Workbooks.Add().WorkSheets.Item(1).Paste();
   } catch(e) {
    alert("出錯(cuò)啦!可能是瀏覽器或者是數(shù)據(jù)量太大咯哦!");
    return;
   }
   appExcel = null;
   oRangeRef = null;
  }
 }

 //打印
 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);
   } catch(e) {
    alert("出錯(cuò)啦!可能是瀏覽器或者是數(shù)據(jù)量太大咯哦!");
    return;
   }
   export.style.display = "";
   print.style.display = "";
  }
 }
</script>

相關(guān)文章

最新評(píng)論