水晶报表的导出

   //导出报表
    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);
        }
    }   

阅读更多
想对作者说点什么? 我来说一句

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

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