国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表

圖片精選

主站蜘蛛池模板: 昔阳县| 慈溪市| 乌兰浩特市| 白朗县| 合水县| 三明市| 隆回县| 安吉县| 黄石市| 论坛| 顺平县| 永安市| 华亭县| 耿马| 称多县| 峨眉山市| 古浪县| 吴堡县| 镶黄旗| 剑川县| 泰和县| 舟曲县| 基隆市| 兴国县| 师宗县| 唐山市| 丹阳市| 克什克腾旗| 梅州市| 清河县| 山阳县| 临城县| 曲靖市| 嘉荫县| 句容市| 博兴县| 宝山区| 合江县| 嘉义县| 临夏县| 咸阳市|