Bootstrap

html中实现打印和Excel导出

< html >
  
< head >
    
< base  href ="<%=basePath%>" >
    
    
< title ></ title >
    
    
< meta  http-equiv ="pragma"  content ="no-cache" >
    
< meta  http-equiv ="cache-control"  content ="no-cache" >
    
< meta  http-equiv ="expires"  content ="0" >     
    
< meta  http-equiv ="keywords"  content ="keyword1,keyword2,keyword3" >
    
< meta  http-equiv ="description"  content ="This is my page" >
    
<!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    
-->
    
< style  media ="print"  type ="text/css" >
.Noprint
{display:none;}
.PageNext
{page-break-after: always;}
</ style >
    
< script  type ="text/javascript" >
    
//导出到Excel
    function toExcel()
    
{
        
var elTable = document.getElementById("tb"); 
        
var oRangeRef = document.body.createTextRange(); 
        oRangeRef.moveToElementText( elTable ); 
        oRangeRef.execCommand( 
"Copy" ); 

        
var appExcel = new ActiveXObject( "Excel.Application" ); 
        appExcel.Visible 
= true
        appExcel.Workbooks.Add().Worksheets.Item(
1).Paste(); 
        appExcel 
= null;
    }

      
//打印
           
     
var HKEY_Root,HKEY_Path,HKEY_Key; 
     HKEY_Root
="HKEY_CURRENT_USER"
     HKEY_Path
="/Software/Microsoft/Internet Explorer/PageSetup/"
     
//设置网页打印的页眉页脚为空 
     function PageSetup_Null()
      

        
try 
        
var Wsh=new ActiveXObject("WScript.Shell"); 
        HKEY_Key
="header"
        Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,""); 
        HKEY_Key
="footer"
        Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,""); 
        }
  catch(e){} 
      }
 
      
//恢复网页打印的页眉页脚
      function PageSetup_default()
      

        
try 
        
var Wsh=new ActiveXObject("WScript.Shell"); 
        HKEY_Key
="header"
        Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,"&w&b页码,&p/&P"); 
        HKEY_Key
="footer"
        Wsh.RegWrite(HKEY_Root
+HKEY_Path+HKEY_Key,"&u&b&d"); 
        }
  catch(e){} 
      }
 
      
</ script >
  
</ head >
  
  
< body  onload ="PageSetup_Null()" >
  
< div  id ='block' >
    
< table  id ="tb" >
        
< tr >    
          
< td > ID </ td >    
          
< td > Name </ td >    
          
< td > Describ </ td >    
        
</ tr >    
        
< tr >    
          
< td > 1 </ td >    
          
< td > name1 </ td >    
          
< td > describ1 </ td >    
        
</ tr >    
        
< tr >    
          
< td > 2 </ td >    
          
< td > name2 </ td >    
          
< td > describ2 </ td >    
        
</ tr >            
    
</ table >
    
</ div >
    
< object  id ="WebBrowser"  classid ="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"  height ="0"
        width
="0" >
    
</ object >
    
    
< center  class ="Noprint"   >
    
< input  type ="button"  value ="打印"  onclick ="document.all.WebBrowser.ExecWB(6,1)"   />
    
< input  type ="button"  value ="直接打印"  onclick ="document.all.WebBrowser.ExecWB(6,6)"   />
    
< input  type ="button"  value ="页面设置"  onclick ="document.all.WebBrowser.ExecWB(8,1)"   />
    
< input  type ="button"  value ="打印预览"  onclick ="document.all.WebBrowser.ExecWB(7,1)"   />
    
</ center >
    
    
< input  type ="button"  value ="导出到Excel"  name ="button1"  onclick ="printScreen(block)" >
  
</ body >
</ html >
 
;