WEB打印經(jīng)驗(yàn)交流
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
WEB打印一直困擾著大家,小弟最近做一項(xiàng)目,稍有心得,特來(lái)跟大家交流交流。 我在那個(gè)項(xiàng)目中是利用ScriptX.cab這個(gè)控件來(lái)解決問(wèn)題的,包括各種匯總表,詳細(xì)清單等等,不過(guò)最大弊端就是打印的格式是死的,你要打印出怎樣的格式必須自己來(lái)做,還有就是打印分頁(yè),它是按你設(shè)置的紙張大小來(lái)分的,所以必須人為控制,我已經(jīng)搞定了。 ScriptX.cab大家可以到網(wǎng)上去DOWN一個(gè)。 好了,廢話不多說(shuō)了,代碼才是大家最需要看到的。 包括三個(gè)文件,一個(gè)是框架頁(yè),一個(gè)是工具欄頁(yè),還一個(gè)就是打印的內(nèi)容頁(yè)了。 框架頁(yè): <html> <head> <title>打印 / 預(yù)覽 / 庫(kù)存匯總表</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> 工具欄頁(yè):([預(yù)覽],[設(shè)置]和[打印]等按鈕,代碼里邊的圖片大家自己去做一個(gè)好了) <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> </td> </tr> </table> </body> 內(nèi)容頁(yè):(代碼里邊的數(shù)據(jù)查詢(xún)請(qǐng)大家換成自己的數(shù)據(jù)查詢(xún)) <style> td{line-height:180%} .ybk{border-right:1px #000000 solid;} .sbk{border-top:1px #000000 solid;} </style> <!--這里調(diào)用控件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 = "" //頁(yè)眉 factory.printing.footer = "" //頁(yè)腳 factory.printing.portrait = false //true為縱向打印,flase為橫向打印 factory.printing.leftMargin = 15.0 //左頁(yè)邊距 factory.printing.topMargin = 5.0 //上頁(yè)邊距 factory.printing.rightMargin = 0.75 //右頁(yè)邊距 factory.printing.bottomMargin = 1.5 //下頁(yè)邊距 } </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 '每頁(yè)記錄條數(shù)即每頁(yè)打印的條數(shù) xs=rs.pagesize rc=rs.pagecount %> <!--自動(dòng)分頁(yè)開(kāi)始--> <% for n = 1 to rc xs_s=(xs*n-xs)+1 '每頁(yè)起始序數(shù) xs_e=xs*n '每頁(yè)結(jié)束序數(shù) %> <p> <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">庫(kù)存匯總表</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">序號(hào)</td> <td width="10%" class="ybk">人工編號(hào)</td> <td width="15%" class="ybk">材料名稱(chēng)</td> <td width="25%" class="ybk">型號(hào)規(guī)格</td> <td width="10%" class="ybk">單價(jià)</td> <td width="8%" class="ybk">數(shù)量</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"> <%=xs_s+(i-1)%></td> <td width="10%" class="ybk"> <%=rs("rgbh")%></td> <td width="15%" class="ybk"> <%=rs("clmc")%></td> <td width="25%" class="ybk"> <%=rs("clxh")%></td> <td width="10%" class="ybk" align="right"><%=FormatNumber(rs("pjj"),3,true)%> </td> <td width="8%" class="ybk" align="right"><%=FormatNumber(rs("kcsl"),2,true)%> </td> <td width="12%" class="ybk" align="right"><%xj=FormatNumber(rs("pjj"),3)*FormatNumber(rs("kcsl"),2)%><%=FormatNumber(xj,2,true)%> </td> <td width="5%" class="ybk"> <%=rs("dw")%></td> <td width="10%"> <%=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"> </td> <td width="10%" class="ybk"> </td> <td width="15%" class="ybk"> </td> <td width="25%" class="ybk"> 本 頁(yè) 合 計(jì)</td> <td width="8%" class="ybk"> </td> <td width="8%" class="ybk"> </td> <td width="12%" class="ybk" align="right"><%=FormatNumber(hj,2,true)%><% hj=0%> </td> <td width="5%" class="ybk"> </td> <td width="10%"> </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"> </td> <td width="10%" class="ybk"> </td> <td width="15%" class="ybk"> </td> <td width="25%" class="ybk"> 總 計(jì)</td> <td width="8%" class="ybk"> </td> <td width="8%" class="ybk"> </td> <td width="12%" class="ybk" align="right"><%=FormatNumber(zj,2,true)%> </td> <td width="5%" class="ybk"> </td> <td width="10%"> <%=now%></td> </tr> <% end if %> </table> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr><td height="15"> </td></tr> <tr><td height="30" align="center"><font size="3">第<%=n%>頁(yè),共<%=rc%>頁(yè)</font></td></tr> </table> </td></tr> </table> <% next %> <!--分頁(yè)結(jié)束--> <% end if rs.close Set rs=Nothing conn.close Set conn=Nothing %> 以上代碼實(shí)現(xiàn)一個(gè)類(lèi)似EXCEL格式的庫(kù)存匯總表打印,大家可以把代碼拷過(guò)去感覺(jué)一下,效果還是不錯(cuò)的,就如我上面所說(shuō),因?yàn)樗拇蛴「袷绞且约鹤龅?,所以大家可以改為自己想要的格式,必須自己做了?/DIV>
歡迎大家交流 ^_^ 關(guān)于ScriptX的下載和該控件的使用方法請(qǐng)登陸http://www.meadroid.com/scriptx/index.asp查看. 本文來(lái)自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/dh20156/archive/2004/12/23/226464.aspx
該文章在 2010/10/9 10:55:18 編輯過(guò) |
關(guān)鍵字查詢(xún)
相關(guān)文章
正在查詢(xún)... |