以编程方式读取CrystalReport的字段值 [英] Reading CrystalReport's Field Value Programmatically

查看:79
本文介绍了以编程方式读取CrystalReport的字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#.NET以编程方式加载Crystal Report文档(该文档从数据库获取数据),然后将其导出为PDF。

I'm using C#.NET to programmatically load a Crystal Report document (which gets its data from a database) and then export it as a PDF.

I试图从报告中读取字段(abc123)值时卡住(我想在文件名中使用它)。我不在乎此字段在水晶报表中的位置;

I'm stuck trying to read a fields (abc123) value from within the report (I want to use it in the filename). I don't mind where this field is in the crystal report; and it will not be repeated, but it needs to be a field in the report.

到目前为止我的代码:

// Setup
ReportDocument reportTemplate = new ReportDocument();
reportTemplate.Load(textBox1.Text);
reportTemplate.Refresh();
reportTemplate.ReadRecords();

// Load the current reports name from the report summary information
String ReportName = reportTemplate.SummaryInfo.ReportTitle.ToString();

// Load the current reports "abc123" field from the report
// ????

// Export the report as PDF
reportTemplate.Export();

我尝试过:

// Load the current reports "abc123" field from the report
String abcField = ((TextObject)rpt.Section2.ReportObjects["abc123"]).Text
String abcField = reportTemplate.ReportDefinition.ReportObjects["abc123"].ToString();
String abcField = reportTemplate.Rows.ReportDocument.ReportDefinition.ReportObjects["abc123"];

没有运气。谁能给一些指点?我可以使用crystalReportView1对象预览报告,并在其中填充字段。

Without luck. Can anyone give some pointers? I can preview the report using crystalReportView1 object and the field is populated there.

推荐答案

不幸的是,您将无法提取计算结果。代码后面的字段值。直到报表引擎接管并进行渲染之后,才能使用计算出的字段值。您可以在呈现报告之前访问/修改公式定义,但不能访问从后面的代码计算出的实际值。即使您添加了一个空白子报表并从主报表中为该字段值向其添加参数,您要访问的字段值在报表引擎呈现它之前也不会具有值。您绝对应该寻找一种从绑定报表的数据中提取数据的方法。

Unfortunately you will not be able to pull a calculated field value from code behind. The calculated field value is not available until after the report engine takes over and does the rendering. You can access/modify formula definitions before the report is rendered but have no access to the actual value calculated from code behind. Even if you add a blank subreport and add a parameter to it from the main report for the field value you are trying to access it will not have a value before the reports engine renders it. You should definitely look for a way to pull it from the data you are binding the report with.

这篇关于以编程方式读取CrystalReport的字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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