Jasper reports 使用表达式合并jasper中的单元格

Jasper reports 使用表达式合并jasper中的单元格,jasper-reports,report,expression,Jasper Reports,Report,Expression,如果我有这样的桌子: ID | details ___________________ 1 | A 2 | B 3 | C 4 | D 5 | E 6 | F 6 | G ID | details ___________________ 1 | A 2 | B 3 | C 4 | D 5 | E 6 | F,G 我想用jasper来展示这张桌子,如下所示: ID | de

如果我有这样的桌子:

ID   |  details
___________________
1    |  A
2    |  B
3    |  C
4    |  D
5    |  E
6    |  F
6    |  G
ID   |  details
___________________
1    |  A
2    |  B
3    |  C
4    |  D
5    |  E
6    |  F,G
我想用jasper来展示这张桌子,如下所示:

ID   |  details
___________________
1    |  A
2    |  B
3    |  C
4    |  D
5    |  E
6    |  F
6    |  G
ID   |  details
___________________
1    |  A
2    |  B
3    |  C
4    |  D
5    |  E
6    |  F,G
如果详图具有相同的id,则合并详图单元


我可以用什么样的表达式在jasper中实现这一点(而不是在query中)?我正在使用jasper 4.5

这可以通过在
$F{ID}
上进行分组来实现,使用a来压缩
$F{detail}
字符串,并在
组页脚
带中显示结果

Scriptlet的示例

public class Scriptlet extends JRDefaultScriptlet {

  public void afterDetailEval() throws JRScriptletException
  {
    String details = (String)this.getVariableValue("detailsWithId");
    String detail = (String)this.getFieldValue("detail");
    StringBuffer sbuffer = new StringBuffer();
    if (details != null)
    {
        sbuffer.append(details);
        sbuffer.append(", ");
    }
    sbuffer.append(detail);
    this.setVariableValue("detailsWithId", sbuffer.toString());
  }
}
jrxml的示例,报告,注意
jasperReport
标记中的
scriptletClass=“Scriptlet”
(类
Scriptlet
需要在类路径中)


数据源的示例

<report>
<entry><id>1</id><detail>A</detail></entry>
<entry><id>2</id><detail>B</detail></entry>
<entry><id>3</id><detail>C</detail></entry>
<entry><id>4</id><detail>D</detail></entry>
<entry><id>5</id><detail>E</detail></entry>
<entry><id>6</id><detail>F</detail></entry>
<entry><id>6</id><detail>G</detail></entry>
</report>

1A
2B
3C
4D
5E
6F
6G
结果