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

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 16:02:38
字體:
供稿:網(wǎng)友
簡單介紹一種可以使用簡單的JS來實(shí)現(xiàn)把網(wǎng)頁中的信息原樣導(dǎo)出到Excel、還可以打印的方法,需要的朋友可以參考下

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

復(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"></object>
  <table cellpadding="0" cellspacing="0">
   <tr>
    <td nowrap="nowrap" colspan="2">
     用戶信息
    </td>
   </tr>
   <tr>
    <td nowrap="nowrap" colspan="1">
     姓名
    </td>
    <td nowrap="nowrap" colspan="1">
     張三
    </td>
   </tr>

   <tr>
    <td nowrap="nowrap" colspan="2">
     <input type="button" value="導(dǎo)出" >
     <input type="button" value="打印" >
    </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("出錯啦!可能是瀏覽器或者是數(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("出錯啦!可能是瀏覽器或者是數(shù)據(jù)量太大咯哦!");
    return;
   }
   export.style.display = "";
   print.style.display = "";
  }
 }
</script>

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 蓬莱市| 尉氏县| 健康| 涡阳县| 天镇县| 大石桥市| 南皮县| 吴川市| 元谋县| 德令哈市| 浙江省| 上饶市| 光泽县| 仁化县| 河源市| 依安县| 梁河县| 米脂县| 云梦县| 拜城县| 神农架林区| 昭觉县| 新余市| 清涧县| 油尖旺区| 自贡市| 靖边县| 剑河县| 德州市| 兰溪市| 上高县| 托克逊县| 临汾市| 容城县| 湄潭县| 读书| 嘉荫县| 达拉特旗| 土默特左旗| 莲花县| 垣曲县|