Jasper Reports:根据字段值动态显示图像 [英] Jasper Reports: showing images dynamically depending on field values

查看:161
本文介绍了Jasper Reports:根据字段值动态显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jasper Reports和iReport来生成我的应用的报告。我需要根据对数据库的查询在报告中显示图像。图像是计划,其他字段代表测量等。

I'm using Jasper Reports and iReport to generate the reports of my app. I need to show images in my report depending on a query on my database. The images are plans and have other fields inside representing measurements, etc.

I.E。有两个图像:IMAGE1和IMAGE2链接到Field_ONE和Field_TWO。

I.E. With two images: IMAGE1 and IMAGE2 linked to Field_ONE and Field_TWO.


  • 如果Field_ONE是!= null,那么我想在文档中显示IMAGE1和图像内的字段;

  • If Field_ONE is != null then i whould like to show IMAGE1 and the fields inside the image in the document;

如果Field_TWO是!= null且Field_ONE等于null,那么我想在之前显示IMAGE1

If Field_TWO is != null and Field_ONE is equal to null then i want to show IMAGE2 in the place where previously showed IMAGE1

如果Field_TWO是!= null而Field_ONE!= null则我想并排显示IMAGE1和IMAGE2。

If Field_TWO is != null and Field_ONE != null then i want to show IMAGE1 and IMAGE2 side by side.

请注意,我可以有5或6张图片,因此如果不使用标记而在它们之间留下空格,则很难涵盖所有可能性。

Note that i could have 5 or 6 images, so it would be really difficult to cover all the possibilities without leaving blank spaces between them only using tag.

简而言之:我需要类似Android中的布局,我可以根据字段动态添加计划,并按照添加计划的顺序生成图像及其相关字段。

In short: i need something like the layout in Android where i can add the plans dynamically depending on the fields and generate the images and their associated fields in the order i added the plans.

我希望你能提供帮助,谢谢!

I hope you can help, thank you!

注意:我可以有多个相同类型的图像,具体取决于报告的结果,所以几乎不可能用图层覆盖它

Note: I could have more than one image of the same type depending on the result of the report, so it's almost impossible cover it with layers

推荐答案

图层(静态)解决方案


  1. 将问题划分为案例。例如,案例1显示图像1,案例2显示图像2和3,案例3显示图像4等...

  2. 对于i到n(对于n个案例)


    • 为案例i创建所有元素。

    • 添加一个新图层,即图层i。如果隐藏了图层窗口,请转到窗口>图层。

    • 选择添加的元素,右键单击发送到图层。选择图层i。

    • 右键单击图层窗口中的图层,然后更新表达时打印。例如, $ F {Field_ONE}!= null

    • 重复。仅供参考,您可以单击图层上的眼睛(在图层窗口中)隐藏适用的元素以隐藏杂乱。

  1. Divide the problem into cases. For example, case 1 show image 1, case 2 show images 2 and 3, case 3 show image 4 etc...
  2. For i to n (for n cases)
    • Create all the elements for case i.
    • Add a new layer, Layer i. Go to Window > Layers if the Layers window is hidden.
    • Select the elements added, right click and Send to layer. Choose layer i.
    • Right click on the layer in the Layers window and update the Print When Expression. For example, $F{Field_ONE} != null
    • Repeat. FYI, you can click on the eye on the layer (in the Layers window) to hide the applicable elements to hide the clutter.

子报告(动态) )解决方案


  1. 创建一个报告,让我们称之为子报告。


    • 将页面的宽度和高度设置为给定记录的图像部分的高度和宽度。

    • 将所有页边距设置为0

    • 将报告列更改为您想要在一行中包含的图像数。

    • 将打印订单更改为水平

  1. Create a report, lets call it subreport.
    • Set the width and height of the page to be the height and width of your image section for a given record.
    • Set the all of the page margins to 0
    • Change the column of the report to the number of images you'd like to have in a single row.
    • Change the print order to 'Horizontal'

  • 将原始报告中的字段链接到子报告中#2中创建的参数。

在我测试之前,我不想发布此解决方案。如果有不清楚的地方,我可以发布我的样本,它有很多行。您需要子报表的原因是您的主报表有1列并垂直填充,但您需要将图像水平填充多列。对于非null的每个字段,子报表查询将以语句顺序返回记录。然后该记录将填入各列。

I didn't want to post this solution until I tested it. I can post my sample, which has many lines, if there is something unclear. The reason you'll need a subreport is because your main report has 1 column and fills vertically but you need the images to fill horizontally across multiple columns. For each field that is not null, the subreport query will return a record in the statement order. The record will then be filled across the columns.

这篇关于Jasper Reports:根据字段值动态显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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