在asp.net中实现水晶报表的导出功能

       其实如果是在windows 的窗体中,水晶报表的Crystalreportviewer本身提供了导出功能,所以可以不需要编写任何代码。
      但是在asp.net中要实现水晶报表的导出功能则稍微有点不同了,需要实现少量的代码,下面是一个代码模版:

None.gif          public   void  Export( string  FileName,  string  Ext)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            ReportDocument reportDocument 
= GetReportDocument();
InBlock.gif            ExportOptions exportOptions 
= new ExportOptions();
InBlock.gif            DiskFileDestinationOptions diskOptions 
= ExportOptions.CreateDiskFileDestinationOptions();
InBlock.gif            exportOptions.ExportFormatType 
= GetExportFormatType(Ext);
InBlock.gif            exportOptions.ExportDestinationType 
= ExportDestinationType.DiskFile;            
InBlock.gif            diskOptions.DiskFileName 
= FileName+"."+Ext;
InBlock.gif            exportOptions.ExportDestinationOptions 
= diskOptions;
InBlock.gif            reportDocument.Export(exportOptions);
ExpandedBlockEnd.gif        }

其中GetExportFormatType()的实现如下:

None.gif      private  ExportFormatType GetExportFormatType( string  ext)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif {
InBlock.gif            
switch (ext)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
case "pdf":
InBlock.gif                     
return ExportFormatType.PortableDocFormat;
InBlock.gif                 
case "rtf":
InBlock.gif                     
return ExportFormatType.RichText;
InBlock.gif                 
case "doc":
InBlock.gif                     
return ExportFormatType.WordForWindows;
InBlock.gif                 
case "xls":
InBlock.gif                     
return ExportFormatType.Excel;
InBlock.gif                 
case "html":
InBlock.gif                     
return ExportFormatType.HTML32;                 
InBlock.gif                
default:
InBlock.gif                    
return ExportFormatType.NoFormat;
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

而GetReportDocument()则是一个返回用户要导出的报表的ReportDocument 对象的函数,用户自己随意去实现。
另外还要注意,FileName的格式必须是:"c:\\crystalreport"  这样的形式。

套用这个代码模版,就可以实现5种格式的报表导出功能;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值