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;

を使用
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>