虽然我意识到我可以在屏幕外显示表单并隐藏它,以及许多其他形式的WinForms hackish魔法,但我宁愿坚持使用zen路径并完成正确的操作。我有一个SSRS本地报告(所以没有服务器),我想让用户选择查看或打印(换句话说,我不想强迫他们查看打印)。不幸的是,当我尝试将它打印为我在代码中显式创建的组件(当然是在using()块内部时)或者如果我尝试实例化我的查看器表单时,ReportViewer控件会抱怨它的“状态”。只是打印而不显示它。
有没有办法做到这一点,能与我好好相处,还是我应该把它展示在屏幕外并继续我的生活?
答案 0 :(得分:22)
我在我的博客上发布了一个示例:http://blogs.msdn.com/brianhartman/archive/2009/02/27/manually-printing-a-report.aspx
LocalReport对象可以独立于ReportViewer控件进行实例化,并直接用于附加到该博客帖子的示例代码中。或者,即使您没有首先在UI中显示报告,也可以传递ReportViewer.LocalReport。
答案 1 :(得分:1)
检查一下,看看它是否有帮助...... http://scruffylookingcatherder.com/archive/2007/12/07/printing-reporting-services-2005-reports.aspx
一点解释:它使用SSRS Web服务将报告呈现给EMF图像,然后将图像发送到打印机。
答案 2 :(得分:0)
请参阅以下链接,对您非常有用 http://social.msdn.microsoft.com/Forums/en-US/9f52d79d-5baf-4e84-97d5-7dbba6623b89/printing-without-the-reportviewer
答案 3 :(得分: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