我使用CrystalReportForm编写的报告是C#。我将其编写为Windows窗体应用程序。 (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();