如果我理解这个问题,你不能在主报告中总结子报告返回的金额,我有同样的问题,我以这种方式解决了。
1.- 创建一个从net.sf.jasperreports.engine.JRDefaultScriptlet扩展的类。并覆盖方法beforeReportInit()
这是这个类的代码。
package com.mem.utils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.jasperreports.engine.JRDefaultScriptlet;
public class SumarizacionSubtotales extends JRDefaultScriptlet {
private final Log log = LogFactory.getLog(getClass());
private Double total;
public Double getTotal() {
return total;
}
public Double add(Double cantidad) {
if(log.isDebugEnabled())log.debug("AGREGANDO LA CANTIDAD : " + cantidad);
this.total += cantidad;
return cantidad;
}
@Override
public void beforeReportInit() throws JRScriptletException {
if(log.isDebugEnabled())log.debug("beforeReportInit");
total = 0.0D;
}
}
2.- 在 ireport 的类路径中添加项目的 jar。

3.- 替换 REPORT scriptlet 的类。

在您的班级的属性中。

3.- 在要打印子报告返回值的组页脚中添加一个具有以下表达式的文本字段。
$P{REPORT_SCRIPTLET}.add( $V{sum_detalles} )
在这种情况下,$V{sum_detalles}是主报表中的一个变量,其中包含子报表返回的值。
4.- 在最后一页页脚中添加另一个具有以下表达式的文本字段。
$P{REPORT_SCRIPTLET}.getTotal()
