简体   繁体   English

Crystal Reports 需要数小时才能通过代码导出到 pdf

[英]Crystal Reports takes hours to export to pdf by code

I´m facing this issue a long time, after months i´m still not able to find any solution.我很长一段时间都面临这个问题,几个月后我仍然找不到任何解决方案。 Here´s the scenario: VS 2019, Framework 4.6 and Crystal reports 13_0_27.这是场景:VS 2019,Framework 4.6 和 Crystal 报告 13_0_27。

The following code takes hours to export a pdf (about 400 pages and 30.000 rows).以下代码需要几个小时才能导出 pdf(大约 400 页和 30.000 行)。 If i open the report with crystal reports and export the document, same query by code, only takes seconds.如果我用水晶报表打开报表并导出文档,通过代码进行相同的查询,只需几秒钟。

I tried a couple things, like ExportToStream and save the stream to file, or exporting direcly to disk and other post did read that "pdfFormatOptions.UsePageRange = True" should help, but same result.我尝试了几件事,例如 ExportToStream 并将 stream 保存到文件,或直接导出到磁盘,其他帖子确实读到“pdfFormatOptions.UsePageRange = True”应该有所帮助,但结果相同。

The code works fine with smalls pdfs with, for example, 100 rows.该代码适用于例如 100 行的小型 pdf。

Informe.Load(Application.StartupPath + @"\informes\report.rpt");

        for (i = 0; i < Informe.Database.Tables.Count; ++i)
        {
            logOnInfo.ConnectionInfo.ServerName = "Server";
            logOnInfo.ConnectionInfo.DatabaseName = "BBDD";
            logOnInfo.ConnectionInfo.UserID = "user";
            logOnInfo.ConnectionInfo.Password = "user";
            Informe.Database.Tables[i].ApplyLogOnInfo(logOnInfo);
        }

        diskOpts.DiskFileName = PDFPath + _cabe.Guid + "_minutos.pdf";
        ExportOptions exportOpts2 = Informe.ExportOptions;
        exportOpts2.DestinationOptions = diskOpts;
        exportOpts2.ExportFormatType = ExportFormatType.PortableDocFormat;
        exportOpts2.ExportDestinationType = ExportDestinationType.DiskFile;
        
        try
        {
            Informe.RecordSelectionFormula = @" {CabeceraFacturas.Guid}='{" + _cabe.Guid.ToString() + "}'";
            //Informe.Export();
            Stream oStream;
            oStream = (Stream)Informe.ExportToStream(ExportFormatType.PortableDocFormat);

            using (FileStream fileStream = File.Create(RutaGeneracionPDF + _cabe.Guid + "_minutos.pdf", (int)oStream.Length))
            {
                byte[] bytesInStream = new byte[oStream.Length];
                oStream.Read(bytesInStream, 0, bytesInStream.Length);
                fileStream.Write(bytesInStream, 0, bytesInStream.Length);
                fileStream.Close();
            }


        }

Thanks!谢谢!

After expending days and hours and headaches i finally did the trick.在花费了数天、数小时和头痛之后,我终于成功了。

in each detail (About 30.000 rows) i had a formula wich calculated some value with two fields of the detail and two from a joined view.在每个细节(大约 30.000 行)中,我有一个公式计算了一些值,其中包含两个细节字段和两个来自连接视图的字段。 the view was the problem when i was exporting by code (Exporting within Crystal Reports worked ok with no delay).当我通过代码导出时,视图是问题(在 Crystal Reports 中导出工作正常,没有延迟)。 I had to create a new table in SQL, inserting all the rows in view in this new table and add this table to report and..voilá, it worked, exported report in seconds.我必须在 SQL 中创建一个新表,将视图中的所有行插入到这个新表中,然后将此表添加到报告中……瞧,它起作用了,在几秒钟内导出了报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM