web上水晶報表9的列印(3)1224

    技术2022-05-11  90

    web上水晶報表的列印著實讓我困擾了好長時間,一個多月前找的一種列印本頁的方法http://blog.csdn.net/daisylh/archive/2005/10/28/518561.aspx在實際需求中應用不大,而我的水晶報表10在使用時就有錯誤(可能與非正版有關吧@_@),只能望而興嘆

    昨天在給客戶安裝時,USER提出了有一報表的設定需要為"中一刀"(A4的一半),今天測試轉入WORD/EXCEL都極不理想;看了長江支流周的文章,WEB列印要在VS.NET2005中實現,看來我的2003沒盼了。。。。。。

    痛定思痛。。。

    暫時研究出在區域網內的小做法(還不曉得在Internet上會怎樣):

    1。設定紙張格式:[開始]->[設定]->[印表機和傳真]->在空白處點右建,選[伺服器內容]->即可建立紙張新格式

    2。在系統固定資料表中建一printer欄位,用來輸入常用印表機名稱

    3。列印按鈕

    page_load事件:

    Button2.Attributes.Add("onclick", "javascript: document.Form1.TextBox1.value=window.showModalDialog('printer.aspx');return confirm('確定列印嗎?');")

     click事件:

    Dim rpt As ReportDocument = Session("report")        'rpt.PrintOptions.PrinterName = TextBox5.Text        'rpt.PrintToPrinter(1, True, 1, 1)        Dim pv() As String = Split(TextBox1.Text, ";")        Dim margins As CrystalDecisions.Shared.PageMargins        If pv(0) > pv(1) Then            If Not IsStartupScriptRegistered("Startup") Then                Page.RegisterStartupScript("Startup", "<script language=javascript>window.alert('列印頁數設定錯誤!@_@')</script>")            End If            Exit Sub        End If

            ' 取得 PageMargins 結構並設定        '  報表的邊界。        margins = rpt.PrintOptions.PageMargins

            margins.leftMargin = pv(4)

            margins.rightMargin = pv(5)

            margins.topMargin = pv(6)

            margins.bottomMargin = pv(7)        ' 套用頁面邊界。        rpt.PrintOptions.ApplyPageMargins(margins)

            ' 選取印表機。        rpt.PrintOptions.PrinterName = pv(3)

            ' 列印報表。將 startPageN 及 endPageN         '  參數設定為 0 即可列印所有頁面。        Try            rpt.PrintToPrinter(pv(2), False, pv(0), pv(1))        Catch exp As LoadSaveReportException            If Not IsStartupScriptRegistered("Startup") Then                Page.RegisterStartupScript("Startup", "<script language=javascript>window.alert('開啟報表檔時發生錯誤!@_@')</script>")            End If        Catch exp As PrintException            If Not IsStartupScriptRegistered("Startup") Then                Page.RegisterStartupScript("Startup", "<script language=javascript>window.alert('列印時發生錯誤,請檢查印表機相關設定!@_@')</script>")            End If        Catch exp As Exception            If Not IsStartupScriptRegistered("Startup") Then                Page.RegisterStartupScript("Startup", "<script language=javascript>window.alert('錯誤來源:" & exp.Source & "!@_@')</script>")            End If        End Try

    4。printer.aspx

    function sendTo() { var a if (document.Form1.RadioButton1.checked==true) {a="0;0;";} else {a= document.Form1.TextBox1.value + ";" + document.Form1.TextBox2.value+";";} a=a+ document.Form1.TextBox3.value+";"+document.Form1.TextBox4.value+";"+document.Form1.TextBox5.value+";"+document.Form1.TextBox6.value+";"+document.Form1.TextBox7.value+";"+document.Form1.TextBox8.value;  window.returnValue = a;  window.close(); }

    <table style="FONT-SIZE: 9pt; WIDTH: 512px; FONT-FAMILY: 新細明體; HEIGHT: 321px"> <TR> <TD style="FONT-WEIGHT: bold; HEIGHT: 31px">印表機名稱</TD> <TD style="HEIGHT: 31px" colSpan="2"><asp:textbox id="TextBox4" runat="server" Width="406px" Font-Names="新細明體" Font-Size="9pt"></asp:textbox></TD> </TR> <TR> <TD style="FONT-WEIGHT: bold; HEIGHT: 153px" rowspan="4">邊界設定</TD> <TD style="WIDTH: 46px; HEIGHT: 27px">上邊界</TD> <TD style="HEIGHT: 27px"> <asp:TextBox id="TextBox5" runat="server" Width="48px" Font-Names="新細明體" Font-Size="9pt" οnkeypress="escapeKey(document.forms[0].TextBox5,1,2)">220</asp:TextBox></TD> </TR> <TR> <TD style="WIDTH: 46px; HEIGHT: 22px">下邊界</TD> <TD style="HEIGHT: 22px"><asp:textbox id="TextBox6" runat="server" Width="48px" Font-Names="新細明體" Font-Size="9pt" οnkeypress="escapeKey(document.forms[0].TextBox6,1,2)">220</asp:textbox></TD> </TR> <TR> <TD style="WIDTH: 46px; HEIGHT: 19px">左邊界</TD> <TD style="FONT-SIZE: 9pt; FONT-FAMILY: 新細明體; HEIGHT: 19px"> <asp:TextBox id="TextBox7" runat="server" Width="48px" Font-Names="新細明體" Font-Size="9pt" οnkeypress="escapeKey(document.forms[0].TextBox7,1,2)">220</asp:TextBox></TD> </TR> <TR> <TD style="WIDTH: 46px; HEIGHT: 7px">右邊界</TD> <TD style="HEIGHT: 7px"> <asp:TextBox id="TextBox8" runat="server" Width="48px" Font-Names="新細明體" Font-Size="9pt" οnkeypress="escapeKey(document.forms[0].TextBox8,1,2)">220</asp:TextBox></TD> </TR> <tr> <td style="FONT-WEIGHT: bold; HEIGHT: 12px" rowspan="2">列印頁數</td> <td style="HEIGHT: 12px" colspan="2"> <asp:radiobutton id="RadioButton1" runat="server" Text="列印全部" Width="96px" GroupName="rb"></asp:radiobutton></td> </tr> <TR> <TD style="WIDTH: 46px; HEIGHT: 30px"><asp:radiobutton id="RadioButton2" runat="server" Text="頁數" GroupName="rb" Checked="True"></asp:radiobutton></TD> <TD style="HEIGHT: 30px">從<asp:TextBox id="TextBox1" runat="server" Width="48px" Font-Names="新細明體" Font-Size="9pt" οnkeypress="escapeKey(document.forms[0].TextBox1,1,0)">1</asp:TextBox><asp:label id="Label1" runat="server">到</asp:label> <asp:TextBox id="TextBox2" runat="server" Width="48px" Font-Names="新細明體" Font-Size="9pt" οnkeypress="escapeKey(document.forms[0].TextBox2,1,0)">1</asp:TextBox></TD> </TR> <tr> <td style="FONT-WEIGHT: bold; HEIGHT: 26px">列印份數:</td> <td colspan="2" style="HEIGHT: 26px"> <asp:TextBox id="TextBox3" runat="server" Width="48px" Font-Names="新細明體" Font-Size="9pt" οnkeypress="escapeKey(document.forms[0].TextBox3,1,0)">1</asp:TextBox></td> </tr> <TR> <TD colspan="3"><INPUT οnclick="sendTo()" type="button" value="確定" style="FONT-WEIGHT: bold; FONT-SIZE: 9pt; FONT-FAMILY: 新細明體"></TD> </TR> </table>


    最新回复(0)