非常规格式数据分组处理

在Jasper报告中处理交易数据时,如何根据组的数量动态展示'+'符号并计算分组小计。当每个组只有一个项目时,不需要显示'+'和计算小计;如果有多个项目,则需要显示'+'并计算小计。解决方案包括在数据源处理阶段调整数据格式,使用SPL脚本进行条件判断和计算。

【问题】

I am new to Jasper report. I am working on the report which shows transaction data in a table. I have several groups in the table (the group number is not fixed), for the 1st item of each group, I don’t need to show the “+” sign before the item’s actual text. If there are more than 1 items for the group, then I need to show the “+” sign before the item’s actual text, and calculate the subtotal for the group items. If there is only 1 item for the group, I don’t need to calculate the subtotal.

In the table, I only show the items for each group, I don’t show each group’s name.

Could someone please advise on how to achieve this? How to show the “+” sign conditionally, and how to calculate the subtotal conditionally?

Thanks!

(for group1)

item1 value1

+item2 value2

subtotal group1

(for group2)

item1 value1

+item2 value2

+item3 value3

subtotal group2

(for group3)

item1 value

【回答】

控制数据是否隐藏可实现这个需求,即整理出 Jasper 需要的数据格式,然后用 table 控件直接呈现。使用 Jasper 的脚本、SQL、存储过程都可以,这里用较简单的 SPL 为例:

ABC
1=myDB1.query(“select Seller,Client,Amount from sOrder where Amount>?”,arg)
2=create(item,value)
3for A1.group(SellerId)>A2.insert(0:A3,if(#>1,“+”)+Client,Amount)
4if A3.len()>1>A2.insert(0,A3.SellerId+“subtotal:”,A3.sum(Amount))
5result A2

A1:从数据库查询数据,arg 是参数

A2:创建由两个字段组成的序表

A3-B3:将查出的数据分组,并逐条插入到序表,大于 1 条时加 + 号

B2-B3:分组记录数大于 1 条时,追加一条统计记录;

A5:返回序表;

​Jasper 可以通过 JDBC 连接集算器,调用脚本方法和调用存储过程一样,详情参考【JasperReport 调用 SPL 脚本】。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值