[英]Launch a Crystal Report from a C# console application
我使用 CrystalReportForm 编写了一份报告是 C#。 我将其写为 Windows Forms 应用程序。 (Visual Studio 2015)。它运行良好,但我需要将其转换为控制台应用程序,以便我可以自动化它。
我使用了 CrystalReportViewer,可能这不是最好的方法。 任何帮助/方向表示赞赏。
DSP = new Classes.DSP_Object(txtStartDate.Text);
var crf = new CrystalReportForm();
var dsp = new CrystalReports.DSP_Report();
((TextObject)dsp.ReportDefinition.Sections["Section1"].ReportObjects
["lblWeekOfHeader"]).Text = DSP.lblWeekOfHeader;
//Lots more assignments of object fields to report
.
.
.
crf.crv1.ReportSource = dsp;
crf.Show();
//The report looks great at this point.
由于您需要从控制台应用程序运行它,因此我不会尝试在控制台应用程序内托管查看器 - 那是行不通的。
相反,您可以从控制台应用程序运行报告,另存为 pdf 并显示 pdf。
生成报告后,您可以执行以下操作:
Process p=new Process();
p.StartInfo.FileName = @"G:\GeneratedCrystalReport.pdf";
p.Start();
这个问题表明我对C#的水晶无知。 这是一个简单的修复。 只需加载文档而不是通过查看器引用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.