2009-04-08 110 views
14

雖然我意識到我可以在屏幕外顯示錶單並隱藏它,以及許多其他形式的WinForms hackish wizardry,但我寧願堅持禪宗之路,把它做好吧。我有一個SSRS本地報告(所以沒有服務器),我想讓用戶選擇查看或打印(換句話說,我不想強​​迫他們查看打印)。不幸的是,ReportViewer控件在嘗試打印它時顯示它的「狀態」,或者作爲我在代碼中顯式創建的組件(當然,在using()塊內)或者如果我試圖實例化我的查看器窗體並只是打印而不顯示它。如何在不顯示錶單的情況下打印ReportViewer的報告

有沒有辦法做到這一點,將與我坐在一起,或者我應該只顯示它​​在屏幕外並繼續我的生活?

回答

22

我有一個樣本,這是否貼在我的博客在這裏:http://blogs.msdn.com/brianhartman/archive/2009/02/27/manually-printing-a-report.aspx

的LocalReport對象可以獨立ReportViewer控件被實例化並直接連接到該博客文章示例代碼中使用。或者即使您不首先在UI中顯示報告,也可以傳入ReportViewer.LocalReport。

+0

謝謝,布賴恩。我明天首先看看這個解決方案。 – 2009-04-12 21:21:23

2

檢查了這一點,看看它是否有助於... http://scruffylookingcatherder.com/archive/2007/12/07/printing-reporting-services-2005-reports.aspx

一點解釋:它使用的SSRS web服務呈現給EMF圖像的報告,然後將圖像發送到打印機。

+0

不幸的是非常有用的,這是一個本地報表使用從DataSet從SQLCE 3.5數據庫中的數據,所以任何與SSRS本身可能出這個問題。 – 2009-04-09 01:16:38

+0

@Mozy您提供的鏈接不起作用。 正確的鏈接是http://scruffylookingcatherder.com/post/2007/12/08/Printing-Reporting-Services-2005-Reports.aspx – N30 2010-01-30 00:07:56

0
Private Sub btnReceipt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReceipt.Click 


    My.Forms.FormA5.ReportViewer.LocalReport.DataSources.Clear() 
    Dim cmd = New SqlClient.SqlCommand("Select * from V_Sale where InvoiceNo=" & Me.txtInvoice.Text, cn) 
    Dim dr = cmd.ExecuteReader() 
    Dim dt As New DataTable 
    dt.Load(dr) 
    dr.Close() 
    Dim rpt As New ReportViewer 
    rpt.LocalReport.DataSources.Clear() 
    rpt.LocalReport.DataSources.Add(New ReportDataSource("posds_receipt", dt)) 
    rpt.LocalReport.ReportEmbeddedResource = "POSsystem.receipt.rdlc" 
    rpt.SetDisplayMode(DisplayMode.PrintLayout) 
    rpt.ZoomMode = ZoomMode.FullPage 

    Dim printDialog1 As PrintDialog = New PrintDialog 
    printDialog1.Document = PrintDocument1 
    Dim result As DialogResult = printDialog1.ShowDialog 
    If (result = DialogResult.OK) Then 
     PrintDocument1.Print() 
    End If 

End Sub 
相關問題