如何使用DynamicJasper在没有组的情况下在JasperReports中显示页脚的每列总和? [英] How to display sum of each columns at footer in JasperReports without groups using DynamicJasper?

查看:220
本文介绍了如何使用DynamicJasper在没有组的情况下在JasperReports中显示页脚的每列总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下方法。

  drb.addGlobalFooterVariable(totalAmount,DJCalculation.SUM); 
drb.addGlobalFooterVariable(basicAmount,DJCalculation.SUM);

但是它显示了最后一行的值(每列的值)而不是页脚中每列的总和(如图所示)。



我错过了什么吗?



解决方案

这是基于


I tried using the method below.

drb.addGlobalFooterVariable(totalAmount, DJCalculation.SUM);
drb.addGlobalFooterVariable(basicAmount, DJCalculation.SUM);

But it shows me the value of last row (of each column) instead of the sum of each column in the footer (as shown in images).

Do I miss something?

解决方案

This is working code based on example from DynamicJasper official site.

DynamicReportBuilder drb = new DynamicReportBuilder();
drb
        .setTitleStyle(titleStyle)
        .setTitle("Report with grand total")
        .setDetailHeight(15).setHeaderHeight(10)
        .setGrandTotalLegend("Grand Total")
        .setGrandTotalLegendStyle(footerStyle)
        .setDefaultStyles(titleStyle, null, headerStyle, detailStyle)
        .setPrintColumnNames(true);

AbstractColumn columnState = ColumnBuilder.getNew()
        .setColumnProperty("state", String.class.getName())
        .setTitle("State").setWidth(85)
        .build();

AbstractColumn columnBranch = ColumnBuilder.getNew()
        .setColumnProperty("branch", String.class.getName())
        .setTitle("Branch").setWidth(85)
        .setStyle(detailStyle).setHeaderStyle(headerStyle)
        .build();

AbstractColumn columnnProductLine = ColumnBuilder.getNew()
        .setColumnProperty("productLine", String.class.getName())
        .setTitle("Product Line").setWidth(85)
        .setStyle(detailStyle).setHeaderStyle(headerStyle)
        .build();

AbstractColumn columnnQuantity = ColumnBuilder.getNew()
        .setColumnProperty("quantity", Long.class.getName())
        .setTitle("Quantity").setWidth(80)
        .setStyle(rightAlignedStyle).setHeaderStyle(headerStyle)
        .build();

AbstractColumn columnAmount = ColumnBuilder.getNew()
        .setColumnProperty("amount", Float.class.getName())
        .setTitle("Amount").setWidth(90).setPattern("$ 0.00")
        .setStyle(rightAlignedStyle).setHeaderStyle(headerStyle)
        .build();

drb.addGlobalFooterVariable(columnAmount, DJCalculation.SUM, footerStyle);
drb.addGlobalFooterVariable(columnnQuantity, DJCalculation.SUM, footerStyle);

drb.addColumn(columnState);
drb.addColumn(columnBranch);
drb.addColumn(columnnProductLine);
drb.addColumn(columnnQuantity);
drb.addColumn(columnAmount);

drb.setUseFullPageWidth(true);

The output result is:

这篇关于如何使用DynamicJasper在没有组的情况下在JasperReports中显示页脚的每列总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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