簡體   English   中英

Crystal Reports 需要數小時才能通過代碼導出到 pdf

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

我很長一段時間都面臨這個問題,幾個月后我仍然找不到任何解決方案。 這是場景:VS 2019,Framework 4.6 和 Crystal 報告 13_0_27。

以下代碼需要幾個小時才能導出 pdf(大約 400 頁和 30.000 行)。 如果我用水晶報表打開報表並導出文檔,通過代碼進行相同的查詢,只需幾秒鍾。

我嘗試了幾件事,例如 ExportToStream 並將 stream 保存到文件,或直接導出到磁盤,其他帖子確實讀到“pdfFormatOptions.UsePageRange = True”應該有所幫助,但結果相同。

該代碼適用於例如 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();
            }


        }

謝謝!

在花費了數天、數小時和頭痛之后,我終於成功了。

在每個細節(大約 30.000 行)中,我有一個公式計算了一些值,其中包含兩個細節字段和兩個來自連接視圖的字段。 當我通過代碼導出時,視圖是問題(在 Crystal Reports 中導出工作正常,沒有延遲)。 我必須在 SQL 中創建一個新表,將視圖中的所有行插入到這個新表中,然后將此表添加到報告中……瞧,它起作用了,在幾秒鍾內導出了報告。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM