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

   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);
 

阅读更多
文章标签: excel 报表 string
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

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

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭