繁体   English   中英

如何在不显示表单的情况下打印ReportViewer的报表

[英]How to print a ReportViewer's report without showing a form

虽然我意识到我可以在屏幕外显示表单并隐藏它,以及许多其他形式的WinForms hackish魔法,我宁愿坚持使用zen路径并完成正确的操作。 我有一个SSRS本地报告(所以没有服务器),我想让用户选择查看或打印(换句话说,我不想强​​迫他们查看打印)。 不幸的是,当我尝试将它打印为我在代码中显式创建的组件(当然是在using()块内部时)或者如果我尝试实例化我的查看器表单时,ReportViewer控件会抱怨它的“状态”。只是打印而不显示它。

有没有办法做到这一点,能与我好好相处,还是我应该把它展示在屏幕外并继续我的生活?

我在我的博客上发布了一个样本: http//blogs.msdn.com/brianhartman/archive/2009/02/27/manually-printing-a-report.aspx

LocalReport对象可以独立于ReportViewer控件进行实例化,并直接用于附加到该博客文章的示例代码中。 或者,即使您没有首先在UI中显示报表,也可以传入ReportViewer.LocalReport。

检查一下,看看它是否有帮助... http://scruffylookingcatherder.com/archive/2007/12/07/printing-reporting-services-2005-reports.aspx

一点解释:它使用SSRS Web服务将报告呈现为EMF图像,然后将图像发送到打印机。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM