水晶报告“文件断开” [英] Crystal Reports "File Break"
问题描述
我生成一个水晶报表报表,最终需要分成数千个pdf文件。如果水晶报表有类似文件断点,像分页符,可以在适当的位置插入文件,那么什么是理想的。
我需要对文件名进行相当精确的控制,以及....fileName_ {CustomerId} _ {CustomerIsLocal} .pdf。
假定可能需要第三方软件。
任何人谁显示寻找答案:
private readonly CrystalReportViewer reportViewer = new CrystalReportViewer
...
this.reportViewer.ReportSource = @C:\PathToReport\Report.rpt;
使用(var crystalReport = new ReportDocument())
{
foreach(dataSet.Tables [0] .Rows中的DataRow行)
{
var customerId = int.Parse(row [customerId]。ToString());
var isCurrent = bool.Parse(row [isCurrent]。ToString());
var totalSales = int.Parse(row [totalSales]。ToString());
//为每行生成报告
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.Design
CrystalDecisions.CrystalReports.Engine
此代码产生如下所示的文件名:
EndOfYear_123456_1.pdf
当然可以为每一行生成报表对象,而不是传递它,但会慢一些。重复使用同一个报表对象对我看不到任何负面影响,并使事情快十倍。
你需要的唯一的另一件事是如何准备一个Crystal报表,这超出了本教程的范围。祝你好运!
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.
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:\PathToReport\Report.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);
}
References:
CrystalDecisions.CrystalReports.Design CrystalDecisions.CrystalReports.Engine
This code yields a filename like so:
"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.
The only other thing you need is how to prepare a Crystal report, which is beyond the scope of this tutorial. Good luck!
这篇关于水晶报告“文件断开”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!