关闭

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

1353人阅读 评论(1) 收藏 举报

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

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:2288767次
    • 积分:26157
    • 等级:
    • 排名:第229名
    • 原创:1篇
    • 转载:1662篇
    • 译文:0篇
    • 评论:98条
    最新评论