【问题标题】:How to print a ReportViewer's report without showing a form如何在不显示表单的情况下打印 ReportViewer 的报告
【发布时间】:2009-04-08 17:46:23
【问题描述】:

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

有什么方法可以让我很满意,还是我应该在屏幕外展示它并继续我的生活?

【问题讨论】:

    标签: c# .net reporting-services


    【解决方案1】:

    我在我的博客上发布了一个执行此操作的示例:http://blogs.msdn.com/brianhartman/archive/2009/02/27/manually-printing-a-report.aspx

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

    【讨论】:

    • 谢谢,布赖恩。明天上班的第一件事就是看看这个解决方案。
    • 优秀的解决方案;工作完美!恭喜您从一个赏金问题中获得了第一个 SO 积分;)
    • 传奇。为我节省了大量时间:)
    • 最后,谢谢...完美运行。很高兴不必使用水晶
    • 不幸的是链接不再有效:​​(@BrianHartman你能提供一个更新的链接吗?
    【解决方案2】:

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

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

    【讨论】:

    • 不幸的是,这是一个本地报告,使用来自 SqlCe 3.5 数据库的 DataSet 中的数据,因此与 SSRS 本身有关的任何事情都可能是不可能的。
    • @Mozy 您提供的链接无效。正确的链接是scruffylookingcatherder.com/post/2007/12/08/…
    【解决方案3】:

    【讨论】:

    • 也许您可以在链接中添加对可用解决方案的描述。
    【解决方案4】:
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-24
      • 2016-04-16
      • 2021-05-17
      • 2011-01-04
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多