一个人的天空

知识就像宇宙,你不知道它到底存在多少奥秘,必须不断的探索
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

水晶报表导出为word,excel和pdf格式

Posted on 2005-12-14 14:42  一个人的天空  阅读(510)  评论(0编辑  收藏  举报

   string filetype = "";
  
   filetype = ddlFileType.SelectedValue;
   
   string contenttype = "";
   
   string myfilename = Request.MapPath(".")+"\\ReportExportFile\\"+Session.SessionID+"."+filetype;

   CrystalDecisions.Shared.DiskFileDestinationOptions mydiskfiledestinationoptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();

   mydiskfiledestinationoptions.DiskFileName = myfilename;
  
   CrystalDecisions.Shared.ExportOptions myExportOptions = myreport.ExportOptions;

   myExportOptions.DestinationOptions = mydiskfiledestinationoptions;
   
   myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;

   switch(ddlFileType.SelectedItem.Value)
   
   {
    
    case "pdf":
     
            contenttype = "application/pdf";
     
            myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
            break;
    
    case "doc":
     
            Response.ContentType = "application/ms-excel";
     
            myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
            break;
    
    case "xls":
     
            contenttype = "application/vnd.ms-excel";

            this.EnableViewState = false;
            myExportOptions.ExportFormatType =CrystalDecisions.Shared.ExportFormatType.Excel;
            break;
   }
   
   myreport.Export();

   Response.ClearContent();
 
   Response.ClearHeaders();
   
   Response.ContentType = contenttype;
   
   Response.WriteFile(myfilename);
   
   Response.Flush();
   
   Response.Close();

   System.IO.File.Delete(myfilename);