【问题标题】:How to Export Crystal report to PDF in local system?如何在本地系统中将 Crystal 报表导出为 PDF?
【发布时间】:2012-10-18 12:10:38
【问题描述】:

我需要以PDF格式将水晶报表导出到本地系统。

我使用了ExporttoDesk,但它保存在服务器中。我需要将其提供给用户。

有可能吗?

我使用了ExporttoStream。但它也不适合我。

请告诉我实现这一目标的方法。

谢谢, 拉克什。

【问题讨论】:

    标签: crystal-reports export-to-pdf


    【解决方案1】:

    点击按钮试试这个

    try
            {
                ExportOptions CrExportOptions ;
                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = "c:\\csharp.net-informations.pdf";
                CrExportOptions = cryRpt.ExportOptions;
                {
                    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                    CrExportOptions.FormatOptions = CrFormatTypeOptions;
                }
                cryRpt.Export();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
    

    阅读其解释here

    【讨论】:

    • 嗨...这是一个网络应用程序,我已经实现了你的代码,但它没有下载任何文件
    【解决方案2】:

    我们有参数怎么办?

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            Dim Report As ReportDocument = New ReportDocument()
            Report.Load(Server.MapPath("~/CrystalReport.rpt"))
            Report.SetDatabaseLogon("sa", "######", "IT250WS", "demo")
            CrystalReportViewer1.ReportSource = Report
        End Sub
    
        Protected Sub btnPDF_Click(ByVal sender As Object, ByVal e As EventArgs)
            Dim Report As ReportDocument = New ReportDocument()
            Report.Load(Server.MapPath("~/CrystalReport.rpt"))
            Report.SetParameterValue("@EmpId", 1)
            Report.SetDatabaseLogon("sa", "######", "IT250WS", "demo")
            Response.Buffer = False
            Response.ClearContent()
            Response.ClearHeaders()
            Report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "File_Name")
            Response.[End]()
        End Sub
    

    【讨论】:

    • 已经有一个回答说你提供了什么。没有理由重复那个答案。
    • @hongsy 在这里我用 Parameter 谈论他在没有参数的情况下提出的问题。希望您能理解并支持我。
    【解决方案3】:

    答案为时已晚,但可能对像我这样的其他人有用。

    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;
    
    protected void Page_Load(object sender, EventArgs e)
        {
            ReportDocument pdfReport = new ReportDocument();
            pdfReport.Load(Server.MapPath("ExportToPdf.rpt"));
            pdfReport.SetDatabaseLogon("amitjain","password", @"AMITJAIN\SQL", "Northwind");
            CrystalReportViewer1.ReportSource = pdfReport;
        }
    
        protected void btnExport_Click(object sender, EventArgs e)
        {
            ReportDocument pdfReport = new ReportDocument();
            pdfReport.Load(Server.MapPath("ExportToPdf.rpt"));
            pdfReport.SetDatabaseLogon("user", "password", @"AMITJAIN\SQL", "Northwind");
            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();
            pdfReport.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Employees");
            Response.End();
        }
    

    http://csharpdotnetfreak.blogspot.com/2012/01/export-crystalreports-to-pdf-word-excel.html

    经过测试并正常工作。

    【讨论】:

    • 欢迎link 提供解决方案,但请确保您的答案在没有它的情况下有用:在链接周围添加上下文,以便您的其他用户知道它是什么以及为什么它在那里如果目标页面不可用,请引用您链接到的页面中最相关的部分。 Answers that are little more than a link may be deleted.
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多