在前文<[所见非所得]使用参数控制水晶报表的部分元素不打印>中,使用了参数结合编程的方法实现。
优快云论坛上的网友提供了另外一种更好的方法
http://topic.youkuaiyun.com/u/20081103/08/4aa67c3a-185b-4f96-8197-1fda53e6c0aa.html?seed=1144679551
方法重点:显示与打印分离,程序中直接设置对象的抑制显示属性。然后打印。
核心语句:
myReport.ReportDefinition.ReportObjects["Text1"].ObjectFormat.EnableSuppress=true;
模板中不再需要使用参数和公式,直接操作即可。以 WinForm 为例,核心代码为
Public
Class
Form2
Private myReport As New ReportDocument
Private Sub ConfigureCrystalReports()
Dim reportPath As String = Application.StartupPath & " / " & " crystalreport2.rpt "
myReport.Load(reportPath)
CrystalReportViewer1.ReportSource = myReport
End Sub
Private Sub Form1_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Load
ConfigureCrystalReports()
End Sub
Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myReport.ReportDefinition.ReportObjects( " Text8 " ).ObjectFormat.EnableSuppress = True
myReport.ReportDefinition.ReportObjects( " Subreport1 " ).ObjectFormat.EnableSuppress = True
myReport.PrintOptions.PrinterName = " Microsoft Office Document Image Writer "
myReport.PrintToPrinter( 1 , False , 1 , 99 )
End Sub
End Class
Private myReport As New ReportDocument
Private Sub ConfigureCrystalReports()
Dim reportPath As String = Application.StartupPath & " / " & " crystalreport2.rpt "
myReport.Load(reportPath)
CrystalReportViewer1.ReportSource = myReport
End Sub
Private Sub Form1_Load( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase .Load
ConfigureCrystalReports()
End Sub
Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myReport.ReportDefinition.ReportObjects( " Text8 " ).ObjectFormat.EnableSuppress = True
myReport.ReportDefinition.ReportObjects( " Subreport1 " ).ObjectFormat.EnableSuppress = True
myReport.PrintOptions.PrinterName = " Microsoft Office Document Image Writer "
myReport.PrintToPrinter( 1 , False , 1 , 99 )
End Sub
End Class
本文介绍了一种改进的方法来控制水晶报表(Crystal Reports)中部分元素的打印与显示。通过直接设置报表对象的抑制显示属性,可以实现在不使用参数和公式的情况下控制报表元素的打印。示例代码展示了如何在WinForm应用中实现这一功能。
4734

被折叠的 条评论
为什么被折叠?



