水晶报表“文件中断" [英] Crystal Reports "File Break"

查看:23
本文介绍了水晶报表“文件中断"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成一份 Crystal Reports 报告,最终需要将其拆分为数千个 pdf 文件.如果 Crystal Reports 有类似文件中断"(如分页符)之类的东西,您可以将其插入到文件中的适当位置,那将是理想的情况.

I'm generating a Crystal Reports report which will ultimately need to be split into thousands of pdf files. What would be ideal would be if Crystal Reports had something like a "file break", like a page break, that you could insert into the file at the appropriate places.

我还需要对文件名进行相当精细的控制......类似于fileName_{CustomerId}_{CustomerIsLocal}.pdf".

I will need reasonably fine control over the file names, as well....something like "fileName_{CustomerId}_{CustomerIsLocal}.pdf".

我推测可能需要第三方软件.想法?

I'm presuming a third-party piece of software will probably be needed. Thoughts?

TIA.

推荐答案

我想把这个记录下来,让其他出现在寻找答案的人:

I wanted to document this for anyone else who shows up looking for the answer:

private readonly CrystalReportViewer reportViewer = new CrystalReportViewer();
...
this.reportViewer.ReportSource = @"C:PathToReportReport.rpt";

using (var crystalReport = new ReportDocument())
{
    foreach (DataRow row in dataSet.Tables[0].Rows)
    {
        var customerId = int.Parse(row["customerId"].ToString());
        var isCurrent = bool.Parse(row["isCurrent"].ToString());
        var totalSales = int.Parse(row["totalSales"].ToString());

        // generate the report for each row
        this.CreateReport(customerId, isCurrent, totalSales, crystalReport);
    }
}

private void CreateReport(int customerId, bool isCurrent, int totalSales, ReportDocument crystalReport)
{
    crystalReport.Load(this.reportViewer.ReportSource.ToString());

    crystalReport.SetParameterValue("customerId", customerId);
    crystalReport.SetParameterValue("isCurrent", isCurrent);
    crystalReport.SetParameterValue("TotalSales", totalSales);

    var fileName = string.Format("EndOfYear_{0}_{1}.pdf", customerId, isCurrent ? 1 : 0);

    var outputPath = Path.Combine(this.txtOutputDirectory.Text, fileName);

    crystalReport.ExportToDisk(ExportFormatType.PortableDocFormat, outputPath);
}

参考资料:

CrystalDecisions.CrystalReports.DesignCrystalDecisions.CrystalReports.Engine

CrystalDecisions.CrystalReports.Design CrystalDecisions.CrystalReports.Engine

这段代码产生一个像这样的文件名:

This code yields a filename like so:

EndOfYear_123456_1.pdf"

"EndOfYear_123456_1.pdf"

当然可以为每一行生成报表对象,而不是将其传入,但会减慢速度.在我看来,重用同一个报表对象并没有任何负面影响,并且让事情进展快了十倍.

It is certainly possible to generate the report object for each row, rather than passing it in, but slows things down quite a bit. Reusing the same report object doesn't have any negative impact as far as I could see, and made things go about ten times faster.

您唯一需要做的另一件事是如何准备 Crystal 报表,这超出了本教程的范围.祝你好运!

The only other thing you need is how to prepare a Crystal report, which is beyond the scope of this tutorial. Good luck!

这篇关于水晶报表“文件中断"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆