关闭

水晶报表的导出

472人阅读 评论(0) 收藏 举报

   //导出报表
    protected void btnExport_Click(object sender, EventArgs e)
    {     
        string contentype = "";
        string ls_FileType;
        //获取下拉框值
        ls_FileType = ddlFormat.SelectedValue;
        string ExportPath;
        string Fname;
        ExportPath = Request.PhysicalApplicationPath + "Exported/";
        if (!Directory.Exists(ExportPath))
        {
            Directory.CreateDirectory(Request.PhysicalApplicationPath +"Exported/");
        }
        Fname = "Funds_rpt_HQ";
        CrystalDecisions.Shared.DiskFileDestinationOptions opts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
        CrystalDecisions.Shared.ExportOptions myExportOptions = ReportDoc.ExportOptions;
        myExportOptions.DestinationOptions = opts;
        myExportOptions.ExportDestinationType =CrystalDecisions.Shared.ExportDestinationType.DiskFile;
        switch (ddlFormat.SelectedItem.Value)
        {
            case "PDF":
                contentype = "application/pdf";
                myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
                break;
            case "DOC":
                contentype = "application/ms-excel";
                myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
                break;
            case "XLS":
                contentype = "application/vnd.ms-excel";
                this.EnableViewState = false;
                myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;
                break;
          }
        Fname = Fname + ddlFormat.SelectedItem.Value;
        opts.DiskFileName = ExportPath + Fname;
        //导出操作
        try
        {
            ReportDoc.Export();
            Page.ClientScript.RegisterStartupScript(this.GetType(), "MessageBox", @"<script>alert('导出成功!');</script>");
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }   

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:14831次
    • 积分:211
    • 等级:
    • 排名:千里之外
    • 原创:7篇
    • 转载:0篇
    • 译文:0篇
    • 评论:3条
    最新评论