2

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

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

可能吗 ?

我用过ExporttoStream。但它也不适合我。

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

谢谢,拉克什。

4

3 回答 3

2

Try this on Button's click

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());
        }

Read its explanation here

于 2012-10-18T12:18:33.210 回答
0

当我们有参数时怎么做?

    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
于 2020-01-23T07:51:05.790 回答
-2

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

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

测试和工作。

于 2018-06-06T14:14:37.227 回答