国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

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

2019-11-20 20:57:32
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

在一些要求不是很高的小項(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>

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 淮安市| 武强县| 道真| 吉林市| 北京市| 宣城市| 叙永县| 颍上县| 轮台县| 清流县| 留坝县| 桐庐县| 吴堡县| 山阴县| 姜堰市| 黄梅县| 望谟县| 疏勒县| 开阳县| 班戈县| 封丘县| 曲阜市| 虞城县| 宝清县| 曲阳县| 封开县| 包头市| 丰宁| 宝兴县| 青田县| 汶川县| 黄平县| 陇川县| 社会| 辽宁省| 江源县| 尼玛县| 忻州市| 庄河市| 通城县| 子长县|