原创

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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://david.blog.csdn.net/article/details/4795317

 今天要写一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();  

 

文章最后发布于: 2009-11-10 20:02:00
展开阅读全文
0 个人打赏
私信求帮助

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

©️2019 CSDN 皮肤主题: 鲸 设计师: meimeiellie

分享到微信朋友圈

×

扫一扫,手机浏览