[所见非所得2]控制水晶报表的部分元素不打印

在前文<[所见非所得]使用参数控制水晶报表的部分元素不打印>中,使用了参数结合编程的方法实现。

CSDN论坛上的网友提供了另外一种更好的方法
http://topic.csdn.net/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

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值