http://www.webasp.net/tech/article_show.asp?id=18121&fieldby=&keyword=

解决方案 »

  1.   

    某位大侠写的页面打印,精华里也有:<!--语言无关 保存成 .HTML 看看-->
    <html>
    <head>
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
    <title>看看</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <!--media=print 这个属性可以在打印时有效-->
    <style media=print>
    .Noprint{display:none;}
    .PageNext{page-break-after: always;}
    </style><style>
    .tdp
    {
        border-bottom: 1 solid #000000;
        border-left:  1 solid #000000;
        border-right:  0 solid #ffffff;
        border-top: 0 solid #ffffff;
    }
    .tabp
    {
        border-color: #000000 #000000 #000000 #000000;
        border-style: solid;
        border-top-width: 2px;
        border-right-width: 2px;
        border-bottom-width: 1px;
        border-left-width: 1px;
    }
    .NOPRINT {
    font-family: "宋体";
    font-size: 9pt;
    }</style></head><body >
    <center class="Noprint" >
      <p>
      <OBJECT  id=WebBrowser  classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2  height=0  width=0>
      </OBJECT>
      <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)>
    </p>
      <p>    <input  type=button  value=打印预览  onclick=document.all.WebBrowser.ExecWB(7,1)>
        <br/>
        </p>
      <hr align="center" width="90%" size="1" noshade>
    </center><table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"  class="tabp">
    <tr>
    <td colspan="3" class="tdp">第1页</td>
        </tr>
    <tr>
      <td width="29%" class="tdp">&nbsp;</td>
      <td width="28%" class="tdp">&nbsp;</td>
          <td width="43%" class="tdp">&nbsp;</td>
      </tr>
    <tr>
      <td colspan="3" class="tdp">&nbsp;</td>
      </tr>
    <tr>
      <td colspan="3" class="tdp"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="50%" class="tdp"><p>这样的报表</p>
              <p>要求够了。</p></td>
              <td>&nbsp;</td>
            </tr>
          </table></td>
      </tr>
    </table>
    <hr align="center" width="90%" size="1" noshade class="NOPRINT" >
    <!--分页-->
    <div class="PageNext"></div>
    <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"  class="tabp">
      <tr>
        <td class="tdp">第2页</td>
      </tr>
      <tr>
        <td class="tdp">看到分页了吧</td>
      </tr>
      <tr>
        <td class="tdp">&nbsp;</td>
      </tr>
      <tr>
        <td class="tdp">&nbsp;</td>
      </tr>
      <tr>
        <td class="tdp"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="50%" class="tdp"><p>这样的报表</p>
                  <p>要求够了。</p></td>
              <td>&nbsp;</td>
            </tr>
        </table></td>
      </tr>
    </table>
    </body>
    </html>
      

  2.   

    <html>
    <head>
    <style type="text/css" media="print">
    DIV.d1 { DISPLAY: none }
    </style>
    </head>
    <body>
    打印可以这样实现(仅作简单示例):
    也可把那个CAB文件下载到本地服务器再引用它.<br>
    在这里加入打印内容及控制分页............
    <div class="d1">
    <OBJECT id="MyPrinter" style="DISPLAY: none" codeBase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext>
    </OBJECT>
    <SCRIPT defer>
    function window.onload() {
    MyPrinter.printing.header = ""
    MyPrinter.printing.footer = ""
    MyPrinter.printing.portrait=true
    MyPrinter.printing.leftMargin =5
    MyPrinter.printing.topMargin = 5
    MyPrinter.printing.rightMargin = 1
    MyPrinter.printing.bottomMargin = 1
    //MyPrinter.printing.paperSize="Letter"
    }
    </SCRIPT>
    <input style="WIDTH: 87px; HEIGHT: 24px" onclick='document.execCommand("print")' type="button" value="打印...">
    <!--  <INPUT onclick=MyPrinter.printing.Print(false) type=button value=打印本頁> -->
    <input name="button" type="button" onClick="MyPrinter.printing.PageSetup()" value="页面设置">
    <INPUT onclick="MyPrinter.printing.Preview()" type="button" value="打印预览">  <br>

    </div>
    </body>
    </html>
      

  3.   

    <HEAD>
    <title>审批车辆资料打印</title>
    <meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
    <meta content="C#" name="CODE_LANGUAGE">
    <meta content="JavaScript" name="vs_defaultClientScript">
    <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    //这里定义一个样式
    <style type="text/css"> @media Screen { .onlyPrint { DISPLAY: none }}
    @media Print { .onlyShow { DISPLAY: none }///这个只显示不打印
    .onlyPrint { PAGE-BREAK-BEFORE: always }///这个是打印不显示}
    </style>
    </HEAD>
    用法:
    <OBJECT id="MyPrinter" style="DISPLAY: none" codeBase="http://www.meadroid.com/scriptx/ScriptX.cab#Version=5,60,0,360" classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" viewastext>
    </OBJECT><table>
    <tr>
    <td class=onlyShow>////这样就只显示不打印了!
    ....................
    </td>
    </tr>
    <tr>
    <td>
    </td class=onluPrint>////这样就只打印不显示!就是说在客户端的页面上看不到,但打印,打印是看的到!你试试!
    .............................
    </tr>
    </table>这个是我以前写的!
      

  4.   

    调用的方法:
    打印:document.all.WebBrowser.ExecWB(6,1)
    页面设置:document.all.WebBrowser.ExecWB(7,1)
    打印浏览:document.all.WebBrowser.ExecWB(8,1)
    直接打印:document.all.WebBrowser.ExecWB(6,6)
      

  5.   

    web打印:
    <html>
    <head>
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
    <title>看看</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <!--media=print 这个属性可以在打印时有效-->
    <style media=print>
    .Noprint{display:none;}
    .PageNext{page-break-after: always;}
    </style><style>
    .tdp
    {
        border-bottom: 1 solid #000000;
        border-left:  1 solid #000000;
        border-right:  0 solid #ffffff;
        border-top: 0 solid #ffffff;
    }
    .tabp
    {
        border-color: #000000 #000000 #000000 #000000;
        border-style: solid;
        border-top-width: 2px;
        border-right-width: 2px;
        border-bottom-width: 1px;
        border-left-width: 1px;
    }
    .NOPRINT {
     font-family: "宋体";
     font-size: 9pt;
    }</style></head><body >
    <center class="Noprint" >
      <p>
      <OBJECT  id=WebBrowser  classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2  height=0  width=0>
      </OBJECT>
      <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)>
    </p>
      <p>    <input  type=button  value=打印预览  onclick=document.all.WebBrowser.ExecWB(7,1)>
        <br/>
        </p>
      <hr align="center" width="90%" size="1" noshade>
    </center><table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"  class="tabp">
     <tr>
      <td colspan="3" class="tdp">第1页</td>
        </tr>
     <tr>
       <td width="29%" class="tdp">&nbsp;</td>
       <td width="28%" class="tdp">&nbsp;</td>
          <td width="43%" class="tdp">&nbsp;</td>
      </tr>
     <tr>
       <td colspan="3" class="tdp">&nbsp;</td>
      </tr>
     <tr>
       <td colspan="3" class="tdp"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="50%" class="tdp"><p>这样的报表</p>
              <p>对一般的要求就够了。</p></td>
              <td>&nbsp;</td>
            </tr>
          </table></td>
      </tr>
    </table>
    <hr align="center" width="90%" size="1" noshade class="NOPRINT" >
    <!--分页-->
    <div class="PageNext"></div>
    <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0"  class="tabp">
      <tr>
        <td class="tdp">第2页</td>
      </tr>
      <tr>
        <td class="tdp">看到分页了吧</td>
      </tr>
      <tr>
        <td class="tdp">&nbsp;</td>
      </tr>
      <tr>
        <td class="tdp">&nbsp;</td>
      </tr>
      <tr>
        <td class="tdp"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="50%" class="tdp"><p>这样的报表</p>
                  <p>对一般的要求就够了。</p></td>
              <td>&nbsp;</td>
            </tr>
        </table></td>
      </tr>
    </table>
    </body>
    </html>