Inclusion and exclusion of subreports (iReport-Jas

2019-04-11 14:51发布

I need to include or exclude a subreport based on a condition. I'm using iReport to create JasperReports. I.e., if a subreport has values, I need to include that subreport, otherwise not. Can anyone please send a sample or tell me how to resolve this.

3条回答
等我变得足够好
2楼-- · 2019-04-11 15:11

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.

查看更多
迷人小祖宗
3楼-- · 2019-04-11 15:11

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.

查看更多
聊天终结者
4楼-- · 2019-04-11 15:25

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

查看更多
登录 后发表回答