打印w/o显示打印选项对话框Crystal Report Report Giewer在我的C#中



i有一个C#应用程序,该应用程序具有形式的Crystal Report查看器。我称该表格并将其传递给我用来更新与Crystal Report关联的参数字段的值,因此只显示了特定的记录。

所有人都可以正常工作,我可以打电话给观众printreport方法来打印报告没有操作员干预。

CrystalForm fs = new CrystalForm(); 
fs.SetCrystalOrderNumParameter(ItemID);
 public partial class CrystalForm : Form
    {
        public CrystalForm()
        {
            InitializeComponent();
        }
        public void SetCrystalOrderNumParameter(string ItemID)
        {
            ParameterFields paramFields = new ParameterFields();
            ParameterField paramField = new ParameterField();
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
            paramField.Name = "ItemID";
            paramDiscreteValue.Value = ItemID;
            paramField.CurrentValues.Add(paramDiscreteValue);
            paramFields.Add(paramField);

            crystalReportViewer1.ParameterFieldInfo = paramFields;
            crystalReportViewer1.PrintReport();
        }
    }

我遇到的问题是我希望能够将值传递给Crystal Report,以便它使用此#来确定应打印报告的副本。

有没有办法使用Crystal Report查看器来执行此操作?

预先感谢您的帮助。

水晶报告查看器本身不提供此功能。

要控制没有对话框弹出的页面,您将必须使用CrystalDecisions.CrystalReports.Engine.ReportDocument类。此类是CrystalReports API用来表示实际的Crystal报告的内容,并且通常将其分配给查看者的ReportSource属性,以告诉查看器要显示什么报告。您可能已经在使用此对象,但是我看不到您从已共享的代码分配报告源的位置。

ReportDocument类具有PrintToPrinter方法,第二个过载看起来像:void PrintToPrinter(int nCopies, bool collated, int startPageN, int endPageN)

nCopies参数允许您指定要打印的报告的数量。报告的打印设置将默认为报告的打印机设置,尽管可以通过ReportDocument实例的PrintOptions属性更改它们。

这是一个简单的代码示例,其中rptpath是您的水晶报告的路径:

var rpt = new ReportDocument();
rpt.Load(rptPath);
rpt.PrintOptions.PrinterName = "MyPrinterName";
//This will print 2 copies of the crystal report.
//You can use the nCopies (first) parameter to specify whatever #
//of copies you wish.
rpt.PrintToPrinter(2, false, 0, 0);

此外,当使用Load()方法使用ReportDocument来加载Crystal Report时,它会自动填充其参数Fields Collection,并使用报告期望的所有参数。然后,您可以像显示的红色一样设置参数值:

rpt.SetParameterValue("ParameterName", value);

最后,如果您想向观众展示此报告,那么您要做的就是以下内容:

viewer.ReportSource = rpt;

其中 rpt是代表报告的 ReportDocument对象,而查看器是您想使用的CrystalDecisions.Windows.Forms.CrystalReportViewer来显示报告。

通过将变量从后面的代码传递到cr报告参数:

可能是这样:

CRPT.SetParameterValue("syear", Servercls.year);
CRPT.SetParameterValue("smonth", Servercls.month);
CRPT.SetParameterValue("sday", Servercls.day);

有关更多信息,请参见此链接

最新更新