WEB打印-------我的搜集

        我利用ScriptX.cab这个控件来解决问题的,包括各种汇总表,详细清单等等,不过最大弊端就是打印的格式是死的,你要打印出怎样的格式必须自己来做,还有就是打印分页,它是按你设置的纸张大小来分的,所以必须人为控制,我已经搞定了。

ScriptX.cab大家可以到网上去DOWN一个。

好了,废话不多说了,代码才是大家最需要看到的。

包括三个文件,一个是框架页,一个是工具栏页,还一个就是打印的内容页了。

 

框架页:

<html>
<head>
<title>打印 / 预览 / 库存汇总表</title>
<link type="text/css" rel="stylesheet" href="style.css">
<script language="javascript" src="main.js"></script>
<script language="javascript">maxwin();</script>
</head>
<frameset rows="42,*" style="border:none">
<frame src="toolbar.asp" name="toolbar" target="mainbar" frameborder="0" scrolling="no" noresize>
<frame src="kc.asp" name="mainbar" target="mainbar" frameborder="0" scrolling="auto" noresize>
</frameset>
</html>

工具栏页:([预览],[设置]和[打印]等按钮,代码里边的图片大家自己去做一个好了)

<body bgcolor="#D4D0C8" topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" onselectstart="return false" oncontextmenu="return false">
    <table width="100%" height="41" cellpadding="0" cellspacing="0" border="0" background="../images/bg_toolbar.gif">
     <tr>
      <td width="10"><img src="../images/bar_toolbar.gif"></td>
      <td width="85" align="center"><img src="../images/ico_print.gif" onmouseover="this.src= ../images/ico_print1.gif " onmousedown="this.src= ../images/ico_print2.gif " onmouseout="this.src= ../images/ico_print.gif " onclick="top.mainbar.factory.printing.Print(false);"></td>
      <td width="2"><img src="../images/line_toolbar.gif"></td>
      <td width="85" align="center"><img src="../images/ico_setup.gif" onmouseover="this.src= ../images/ico_setup1.gif " onmousedown="this.src= ../images/ico_setup2.gif " onmouseout="this.src= ../images/ico_setup.gif " onclick="top.mainbar.factory.printing.PageSetup();"></td>
      <td width="2"><img src="../images/line_toolbar.gif"></td>
      <td width="85" align="center"><img src="../images/ico_view.gif" onmouseover="this.src= ../images/ico_view1.gif " onmousedown="this.src= ../images/ico_view2.gif " onmouseout="this.src= ../images/ico_view.gif " onclick="top.mainbar.factory.printing.Preview();"></td>
      <td width="2"><img src="../images/line_toolbar.gif"></td>
      <td>&nbsp;</td>
     </tr>
    </table>
</body>

内容页:(代码里边的数据查询请大家换成自己的数据查询)

<style>
td{font-size:14px;line-height:180%}
.ybk{border-right:1px #000000 solid;}
.sbk{border-top:1px #000000 solid;}
</style>
<!--这里调用控件ScriptX.cab-->
<object id="factory" style="display:none" viewastext classid="clsid:1663ed61-23eb-11d2-b92f-008048fdd814" codebase="ScriptX.cab#Version=5,60,0,360"></object>
<script defer>
function window.onload() {
  factory.printing.header = ""         //页眉
  factory.printing.footer = ""        //页脚
  factory.printing.portrait = false    //true为纵向打印,flase为横向打印
  factory.printing.leftMargin = 15.0   //左页边距
  factory.printing.topMargin = 5.0     //上页边距
  factory.printing.rightMargin = 0.75  //右页边距
  factory.printing.bottomMargin = 1.5  //下页边距
  }
</script>
<body oncontextmenu="return false">

        <!--#include file="conn.asp"--

>
        <%
           sql="exec showkc_print"
           Set rs=Server.CreateObject("Adodb.Recordset")
           rs.open sql,conn,3,2
           If Not rs.eof then
              rs.pagesize=21 每页记录条数即每页打印的条数
              xs=rs.pagesize
              rc=rs.pagecount %>


<!--自动分页开始-->

<% for n = 1 to rc
   xs_s=(xs*n-xs)+1 每页起始序数
   xs_e=xs*n 每页结束序数 %>
<p>&nbsp;
<table width="1000" height="700" cellpadding="0" cellspacing="0" border="0">
<tr><td valign="top">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr><td height="50" align="center" valign="top"><font size="5">库存汇总表</font></td></tr>
</table>

<table width="1000" cellpadding="0" cellspacing="0" style="border:1px #000000 solid" align="center">
 <tr height="20" align="center">
  <td width="5%" class="ybk">序号</td>
  <td width="10%" class="ybk">人工编号</td>
  <td width="15%" class="ybk">材料名称</td>
  <td width="25%" class="ybk">型号规格</td>
  <td width="10%" class="ybk">单价</td>
  <td width="8%" class="ybk">数量</td>
  <td width="12%" class="ybk">金额</td>
  <td width="5%" class="ybk">单位</td>
  <td width="10%">更新日期</td>
 </tr>
<%
   dim i
   i=1
   Do While Not rs.eof and i<=xs %>
 <tr><td colspan="10" height="1"><img src="../images/dot.gif" width="100%" height="1"></td></tr>
 <tr height="20">
  <td width="5%" class="ybk">&nbsp;&nbsp;<%=xs_s+(i-1)%></td>
  <td width="10%" class="ybk">&nbsp;&nbsp;<%=rs("rgbh")%></td>
  <td width="15%" class="ybk">&nbsp;<%=rs("clmc")%></td>
  <td width="25%" class="ybk">&nbsp;<%=rs("clxh")%></td>
  <td width="10%" class="ybk" align="right"><%=FormatNumber(rs("pjj"),3,true)%>&nbsp;</td>
  <td width="8%" class="ybk" align="right"><%=FormatNumber(rs("kcsl"),2,true)%>&nbsp;</td>
  <td width="12%" class="ybk" align="right"><%xj=FormatNumber(rs("pjj"),3)*FormatNumber(rs("kcsl"),2)%><%=FormatNumber(xj,2,true)%>&nbsp;</td>
  <td width="5%" class="ybk">&nbsp;<%=rs("dw")%></td>
  <td width="10%">&nbsp;<%=datevalue(rs("gxsj"))%></td>
 </tr>

<%
   rs.MoveNext
   i=i+1
   hj=hj+xj
   zj=zj+xj
   Loop %>

 <% If rc>1 then %>
 <tr><td colspan="10" height="1"><img src="../images/dot.gif" width="100%" height="1"></td></tr>
 <tr height="20">
  <td width="5%" class="ybk">&nbsp;</td>
  <td width="10%" class="ybk">&nbsp;</td>
  <td width="15%" class="ybk">&nbsp;</td>
  <td width="25%" class="ybk">&nbsp;本 页 合 计</td>
  <td width="8%" class="ybk">&nbsp;</td>
  <td width="8%" class="ybk">&nbsp;</td>
  <td width="12%" class="ybk" align="righ

t"><%=FormatNumber(hj,2,true)%><% hj=0%>&nbsp;</td>
  <td width="5%" class="ybk">&nbsp;</td>
  <td width="10%">&nbsp;</td>
 </tr>
 <% end if %>


 <% If n=rc then %>
 <tr><td colspan="10" height="1"><img src="../images/dot.gif" width="100%" height="1"></td></tr>
 <tr height="20">
  <td width="5%" class="ybk">&nbsp;</td>
  <td width="10%" class="ybk">&nbsp;</td>
  <td width="15%" class="ybk">&nbsp;</td>
  <td width="25%" class="ybk">&nbsp;总 计</td>
  <td width="8%" class="ybk">&nbsp;</td>
  <td width="8%" class="ybk">&nbsp;</td>
  <td width="12%" class="ybk" align="right"><%=FormatNumber(zj,2,true)%>&nbsp;</td>
  <td width="5%" class="ybk">&nbsp;</td>
  <td width="10%">&nbsp;<%=now%></td>
 </tr>
 <% end if %>

</table>

<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr><td height="15">&nbsp;</td></tr>
  <tr><td height="30" align="center"><font size="3">第<%=n%>页,共<%=rc%>页</font></td></tr>
</table>
</td></tr>
</table>
<% next %>

<!--分页结束-->

<%        
           end if
           rs.close
           Set rs=Nothing
           conn.close
           Set conn=Nothing %>

以上代码实现一个类似EXCEL格式的库存汇总表打印,大家可以把代码拷过去感觉一下,效果还是不错的,就如我上面所说,因为它的打印格式是要自己做的,所以大家可以改为自己想要的格式,必须自己做了。

posted @ 2006-05-12 15:17  郭大少  阅读(...)  评论(...编辑  收藏