[水晶报表]导出各种报表到指定目录

 今天要写一ECN项目的时候需要用到导出的功能:

在网络上找了一些资料。结合自己的情况修改调试一下了 先看看效果吧

 

 

 

写到页面上了。再看看是否写到指定目录了?

OK 成功了 一下是代码

----------------------------------------------------------以下为报表加载  

     .....
string reportPath = Server.MapPath("..//Reports//project.rpt");
        //doc.Load(@"C:/test/1.rpt");
        doc.Load(reportPath);
        doc.SetDataSource(ds.Tables[0]);
        CrystalReportViewer1.ReportSource = doc;
        CrystalReportViewer1.DataBind();


----------------------------------------------------------实现生成指定格式的文件到指定目录
        

string filetype = "";
        filetype = ddl_FileFormat.SelectedValue;
        string contenttype = "";
        //string myfilename = Request.MapPath(".//") + Session.SessionID + "." + filetype;//目录地址 注意反义字符
        string myfilename = "C://test//" + Session.SessionID  +"." + filetype;
        CrystalDecisions.Shared.DiskFileDestinationOptions mydiskoptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();
        mydiskoptions.DiskFileName = myfilename;
        CrystalDecisions.Shared.ExportOptions myExportOptions = new ExportOptions();//oCR.ExportOptions; 
        myExportOptions.DestinationOptions = mydiskoptions;
        myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
        switch (ddl_FileFormat.SelectedItem.Value) //类别
        {
            case "pdf":
                contenttype = "application/pdf";
                myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                break;
            case "doc":
                contenttype = "application/msword";
                myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
                break;
            case "XLS":
                contenttype = "application/vnd.ms-excel";
                myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;
                break;
            case "RTF":
                contenttype = "application/rtf";
                myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.RichText;
                break;
                
        }
        doc.Export(myExportOptions); //输出报表 到服务器端的制定路径 
        Response.ClearContent();     //清空页面 
        Response.ClearHeaders();
        Response.ContentType = contenttype;
        Response.WriteFile(myfilename);//直接写入页面,页面平铺 可实现在线阅读功能
        Response.Flush();
        Response.Close();  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

厦门德仔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值