如何在没有 CrystalReportViewer 的情况下查看 Crystal 报告?

How to view Crystal Report without CrystalReportViewer?

我有一个 Web 应用程序,我只需要在其中查看嵌入在网页中的报告。我不需要 CrystalReportViewer 打印、缩放、分页等辅助控件。它的外观应该像扫描的文档图片。有帮助吗?

是的,这是可能的。这是将 crystal 报告对象(在内存流中)转换为 Pdf、Word 或 Excel.

的代码片段
        using CrystalDecisions.Web;
        using CrystalDecisions.Shared;
        using CrystalDecisions.CrystalReports.Engine;

        ReportDocument rpt = new ReportDocument();
        string path2 =  path + reportName;
        rpt.Load(path2);
        CrystalDecisions.CrystalReports.Engine.Database crDatabase = rpt.Database;
        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.ServerName = server;
        crConnectionInfo.DatabaseName = db;
        crConnectionInfo.UserID = crystalUser;
        crConnectionInfo.Password = pwd;
        crConnectionInfo.IntegratedSecurity = false;

        <<<<<<report logic here>>>>>>>>>>>

        CrystalDecisions.Shared.ExportFormatType typ = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
        if (exportFormatType == "doc")
            typ = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
        if (exportFormatType == "xls")
            typ = CrystalDecisions.Shared.ExportFormatType.Excel;

        MemoryStream ms = (MemoryStream)rpt.ExportToStream(typ);