Web下实现打印、打印预览、打印设置、导出到Excel

 常用JS打印:

var printContent = $("printtable").innerHTML;
		var bodyContent = document.body.innerHTML;
		document.body.innerHTML = printContent;
		window.print();
		document.body.innerHTML = bodyContent;
		window.location.reload();
		return;

使用<OBJECT id=wb height=0 width=0
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 name=wb></OBJECT>
<CENTER>

1、打印 onclick=window.print()

2、打印预览 onclick=wb.execwb(7,1)

3、打印页面设置 onclick=wb.execwb(8,1)

打印前把不需要打印的页面设置为隐藏

 

示例:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>薪资等级各项目明细</TITLE>
<META http-equiv=Content-Type content="text/html; charset=GB2312">
<META http-equiv=Pragma content=no-cache>
<META http-equiv=Cache-Control content=no-cache>
<META http-equiv=Expires content=0>
<STYLE type=text/css>TD {
	FONT-SIZE: 12px; FONT-FAMILY: "宋体"; WORD-WRAP: break-word
}
.tbl {
	BORDER-TOP: #cecfce 1px solid; BACKGROUND: #efefef
}
.link1 {
	COLOR: #000000; TEXT-DECORATION: none
}
.link1:hover {
	TEXT-DECORATION: underline
}
 
@media Print    
{
.noprint {
	DISPLAY: none
}
 
}
</STYLE>
 
<SCRIPT> 
function exportToExcel(idDataObj){
    var oXL=new ActiveXObject("Excel.Application");
    var oWB=oXL.Workbooks.Add();
    var oSheet=oWB.ActiveSheet;
    var sel=document.body.createTextRange();
    sel.moveToElementText(idDataObj);
    sel.select;
    sel.execCommand("Copy");
    oSheet.paste();
    oXL.Visible=true;
    oSheet=null;
    oWB=null;
    appExcel=null;
}
</SCRIPT>
 
<META content="MSHTML 6.00.2900.3157" name=GENERATOR></HEAD>
<BODY text=#000000 bgColor=#ffffff>
<OBJECT id=wb height=0 width=0 
classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 name=wb></OBJECT>
<CENTER>
<TABLE class=noprint cellSpacing=0 cellPadding=3 width="95%" align=center 
border=0>
  <TBODY>
  <TR>
    <TD align=right><A class=link1 onclick=exportToExcel(divData) 
      href="#">导出为Excel</A>  
      <A class=link1 onclick=window.print() 
      href="#">打印</A>  
      <A class=link1 onclick=wb.execwb(7,1) 
      href="#">打印预览</A>  
      <A class=link1 onclick=wb.execwb(8,1) 
      href="#">打印页面设置</A></TD></TR></TBODY></TABLE>
<TABLE class=noprint cellSpacing=0 cellPadding=0 width="95%" align=center 
border=0>
  <TBODY>
  <TR>
    <TD align=middle bgColor=#639ace height=1></TD></TR>
  <TR>
    <TD> </TD></TR></TBODY></TABLE>
<DIV id=divData>
<TABLE cellSpacing=0 cellPadding=3 width="95%" border=0>
  <TBODY>
  <TR>
    <TD style="PADDING-BOTTOM: 10px" align=middle colSpan=6><FONT face=黑体 
      size=4>薪资项目明细表</FONT></TD></TR></TBODY></TABLE>
<TABLE id=tblData style="BORDER-COLLAPSE: collapse" borderColor=#000000 
cellSpacing=0 cellPadding=5 width="95%" border=1>
  <TBODY>
  <TR vAlign=center align=middle>
    <TD noWrap>薪资等级</TD>
     
    <TD noWrap>基本工资</TD>
    
    <TD noWrap>考勤奖金</TD>
    
    <TD noWrap>考勤奖金扣减</TD>
    
    <TD noWrap>绩效奖金</TD>
    
    <TD noWrap>绩效调增</TD>
    
    <TD noWrap>绩效调减</TD>
    
    <TD noWrap>计量津贴</TD>
    
    <TD noWrap>工资调增</TD>
    
    <TD noWrap>工资调减</TD>
    
    <TD noWrap>代扣项目</TD>
    
    </TR>
    
  <TR vAlign=center align=middle onMouseOut="this.style.background='';" onMouseOver="this.style.background='#EEE';">
    <TD noWrap>零级</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>-</TD>
    
  </TR>
  
  <TR vAlign=center align=middle onMouseOut="this.style.background='';" onMouseOver="this.style.background='#EEE';">
    <TD noWrap>一级</TD>
    
    <TD noWrap>1600.00</TD>
    
    <TD noWrap>1000.00</TD>
    
    <TD noWrap>100.00</TD>
    
    <TD noWrap>2400.00</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>500.00</TD>
    
    <TD noWrap>-</TD>
    
    <TD noWrap>500.00</TD>
    
  </TR>
  
</TBODY></TABLE></DIV>
<P></P></CENTER></BODY></HTML>


 

 

你可能感兴趣的:(html,Web,Excel,null,Class,border)