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

string filetype = "";
  
   filetype = ddlFileType.SelectedValue;
   
   string contenttype = "";
   
   string myfilename = Request.MapPath(".")+"file://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);

posted @ 2007-05-09 15:24  寒天飞雪  阅读(243)  评论(0编辑  收藏  举报