Inclusion and exclusion of subreports (iReport-JasperReports)

久未见 提交于 2019-12-04 16:24:34
Jamie Love

you can in the master report get data from your data source that allows you to identify if the subreport should be included, then use the 'printWhenExpression' field on the subreport element to check that data.

I use this regularly - for example the printWhenExpression field may contain:

new Boolean($F{TOTAL_STATS}.intValue() != 0)

where TOTAL_STATS is from the master report's database query. If non-zero we show a subreport detailing some data.

From my knowledge, if there aren't any data printed in the subreport, Jasper eliminates the blank space. In other words, if your subreport would normally occupy half a page, but there is no data, then the empty space is eliminated. I'm not sure this is what you mean by including or excluding the report.

Another solution would be to place the subreport in the main report, and from right-click ->properties -> Subreport tab, you select the "Subreport condition" tab and write your condition there. If the condition is true, the content of the subreport will be printed, otherwise it won't be printed.

Jamie Love's answer about "printWhenExpression" is on target.

if there aren't any data printed in the subreport, Jasper eliminates the blank space

Actually, at least in JasperReports 3.7.0 there is a subreport property "Remove Line When Blank" that controls that behavior. By default - at least when I use iReport - that parameter is off.

WEG

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!