如何在 Jasper Report 中创建树结构?

How to create tree structure in Jasper Report?

我需要在报表中显示分层数据结构。

像这样

我的数据结构是:

class X
{
    List<Y> list;
}

class Y
{
   List<Z> list
}

jasper 报告中这是如何实现的?

我们有同样的问题,在搜索了一段时间后,我们决定使用 jasper-report html 组件来解决它。它的作用是,它允许我们在报告中添加 html 内容。因此,我们生成了 html 内容并将其存储在数据库中。并在 jasper 报告中插入 html 数据。希望这可以帮助。

通常使用子报表(或列表/table 组件)使用您展示的数据结构实现这种布局

结构为:

  1. 主报告,迭代所有 x 包括 subreport 1 用于 yz 传递 List<Y> list 作为数据源。

  2. 子报表 1,迭代所有 y,包括一个 subreport 2 for z,将 List<Z> list 作为数据源传递。

  3. 子报表 2,迭代所有 z.

要生成数据源,JRBeanCollectionDataSource 可以为您提供很好的示例 new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{list})

要实现 rowspan 使用 reportElement 上的 stretchType 属性(RelativeToBandHeight 或 RelativeToTallestObject)

例子

<textField>
    <reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="20" uuid="bf6b550c-f37d-4e10-b8dd-1d91c4e6905a"/>
    <textElement verticalAlignment="Middle"/>
        <font size="12"/>
    </textElement>
    <textFieldExpression><![CDATA[$F{x}]]></textFieldExpression>
</textField>

您不喜欢子报表,对于一级结构,可以使用 <jr:list> 组件,请参阅 samples