iReport子报表返回值

发布于 2024-12-05 09:15:46 字数 479 浏览 11 评论 0原文

我正在使用 iReport 4.0.2,我想在我的主报告中显示结果。例如,在我的主报告中,我们有两列,我想获得这两列的总和,就像这样的格式:

A      B     sum
10     5      15

其中 A 是主报告中的一个字段,B 是我的子报告的返回值。 这效果很好。但是,关键是有时子报表不会返回任何值,这就是问题所在。在这种情况下, sum 的结果是这样的:

A       B      sum
10             NULL

正如我们在这里看到的, B 是子报表返回值,但它的值既不是 NULL 也不是 0 。这就是我们遇到这个问题的原因。

我试图找到当SQL没有返回结果时如何从子报表中获取返回值。我知道 iReport 有一个名为“当没有数据时”的属性,但它没有帮助。 所以我想知道,我们是否有其他方法来解决iReport中的问题,或者使用一些SQL技巧。

I am using iReport 4.0.2 and I want to show a result in my main report. For example, in my main report we have two columns and I want to get the sum of that two columns, just like this format:

A      B     sum
10     5      15

Where A is one field in the main report and B is a return value of my subreport.
This works well. But, the key point is that sometimes subreport will not return any value, which is the problem. In this case, the result of sum is like this:

A       B      sum
10             NULL

As we see here, B is the subreport return value but it's value neither NULL nor 0 . That's why we have that problem.

I try to find how can I get the return value from subreport when the SQL returns no results. I know iReport has a property named 'When No Data', but it doesn't help.
So I want to know, whether we have another way to solve the problem in iReport or using some SQL skills.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寂寞美少年 2024-12-12 09:15:46

我认为在你的第二个示例中 B 实际上为空,但也许你的文本字段设置了“空时空白”属性。除了 B 的空白之外,我能够重现您的结果。

真正的问题是您不能使用空值进行加法或减法。 JasperReports 将只打印 null。如果表达式中的变量之一为 null,则必须添加一些逻辑来提供默认值。例如

$F{MAIN_REPORT_FIELD} - ($V{SUB_RESULT} == null ? 0 : $V{SUB_RESULT})

,不幸的是,对于在 JasperReports 4.0.2 中使用 Groovy 表达式的报表来说,这会被破坏(Case 0005138)并且将始终返回 null。

您有几个选择:

  1. 您可以升级到 JasperReports/iReport 4.1.1 来解决此问题。
  2. 您可以切换到使用 Java 进行表达式。

    根据您的报告,这可能会很轻松,也可能会很麻烦。任何没有正确表达式类的字段都必须进行修复,并且您可能必须在对非基元/包装类型执行操作的任何表达式中更加明确。

I think that in your second example B is actually null but perhaps your text field has the 'Blank When Null' property set. I was able to reproduce your results except for the blank for B.

The real issue is that you can't add or subtract with a null value. JasperReports will just print null. You have to add some logic to provide a default value if one of the variables in the expression is null. For example

$F{MAIN_REPORT_FIELD} - ($V{SUB_RESULT} == null ? 0 : $V{SUB_RESULT})

Unfortunately, this is broken for reports that use Groovy for expressions in JasperReports 4.0.2 (Case 0005138) and will always return null.

You have a few options:

  1. You could upgrade to JasperReports/iReport 4.1.1 which resolves this issue.
  2. You could switch to using Java for expressions.

    Depending on your report this will either be painless or it will be a chore. Any fields that don't have the correct Expression Class will have to be fixed up and you'll probably have to be more explicit in any expression that performs operations on non primitive/wrapper types.

陈甜 2024-12-12 09:15:46
  1. 如果您正在主报告中对主字段和子报告字段进行求和,则在求和表达式中 (主报告字段 + (subreportfield==null ? 0 : subreportfield) 。

  2. 将子报表值返回到主报表变量。

字段和裸端口返回变量进行求和,

执行与上面给出的相同的条件。

  1. if you are doing sum of main field and sub report field in main report then in the sum expression (main report field + (subreportfield==null ? 0 : subreportfield) .

  2. return subreport values to main report variable.

Then do the sum of the main report field and bareport return variable.

Do the same condition as given above.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文