报表动态绑定和导出

为报表数据集填充数据:
//strProvider为连接字符串
string strProvider = "Server=(local);DataBase=pubs;UID=sa;PWD=";  
CrystalReport1 oCR = new CrystalReport1();  
Dataset1 ds = new Dataset1();  
SqlConnection MyConn = new SqlConnection(strProvider);  
MyConn.Open();  string strSel = "Select * from Stores";  
SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,MyConn);  
MyAdapter.Fill(ds,"stores");  
oCR.SetDataSource(ds);  
this.CrystalReportViewer1.ReportSource = oCR;

使用pull模式导出报表:
你能够将报表文件导出成为下列格式:
      1. PDF (Portable Document Format)
      2. DOC (MS Word Document)
      3. XLS (MS Excel Spreadsheet)
      4. HTML (Hyper Text Markup Language – 3.2 or 4.0 compliant)
      5. RTF (Rich Text Format)
代码如下:
{
CrystalReport1 myReport= New CrystalReport1()  '注意:这里我们建立一个strong-typed的水晶报表实例。  
CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts= New CrystalDecisions.Shared.DiskFileDestinationOptions()  
myReport.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile  ' 导出成为其它文件时也需要这个选项  ' 如Microsoft Exchange, MAPI等.     
myReport.ExportOptions.ExportFormatType = CrystalDecisions. [Shared].ExportFormatType.PortableDocFormat  '这里我们导出成为.pdf格式文件,你也能选择上面的其它类型文件    
DiskOpts.DiskFileName = "c:/Output.pdf"  '如果你不指定确切的目录,那么文件就会保存到[Windows]/System32目录中去了    
myReport.ExportOptions.DestinationOptions = DiskOpts  '水晶报表文件不包含直接的FileName属性,因此你不能直接指定保存的文件名  '所以你不得不使用DiskFileDestinationOptions对象,设置它的DiskFileName属性  '为你想要的路径,最后将水晶报表的DestinationsOptions属性指定为上面的DiskFileDestinationOption    
myReport.Export()  '上面的代码将完成导出工作。
}

使用PUSH模式导出水晶报表:
当导出的报表是由PUSH模式建立的时,第一步就是通过编程建立连接并组装DataSet,设置报表的的SetDataSource属性。再下面的步骤就有Pull模式一样的了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值