JasperReports的iReport - 产生了一个总计 [英] JasperReports' iReport - generating a grand total

查看:116
本文介绍了JasperReports的iReport - 产生了一个总计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在组页脚区域中设置了一个变量数据类型,它为报表中的每个组中的计数生成小计。效果很好。
我想在报告的最后一页生成一个总计,简单地总结小计值。这很难弄明白。
有什么建议吗?

I have a variable datatype set up in the group footer band that generates a subtotal for the counts in each group in my report. Works great. I would like a grand total to generate on the last page of my report, simply summing up the subtotal values. This has been harder to figure out. Any suggestions?

推荐答案

您可以使用两个不同的 resetType - 用于计算组中的总和(使用 resetType =GroupresetGroup =groupNamecalculation =Sum properties)和计算整个报告的总和(使用 resetType =报告计算=总和 属性)。

You can use two variables with different resetType - for calculating sum in group (with resetType="Group" resetGroup="groupName" calculation="Sum" properties) and for calculating total sum for whole report (with resetType="Report" calculation="Sum" properties).

样本( jrxml 文件):

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="grand_total_sample" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isIgnorePagination="true">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[SELECT DOCUMENTID, POSITIONNO, PRODUCTID, QUANTITY FROM POSITIONS WHERE PRODUCTID < 10 AND POSITIONNO > 18 ORDER BY POSITIONNO]]>
    </queryString>
    <field name="DOCUMENTID" class="java.lang.Integer"/>
    <field name="POSITIONNO" class="java.lang.Integer"/>
    <field name="PRODUCTID" class="java.lang.Integer"/>
    <field name="QUANTITY" class="java.lang.Integer"/>
    <variable name="quantitySumInGroup" class="java.lang.Integer" resetType="Group" resetGroup="positionNoGroup" calculation="Sum">
        <variableExpression><![CDATA[$F{QUANTITY}]]></variableExpression>
        <initialValueExpression><![CDATA[0]]></initialValueExpression>
    </variable>
    <variable name="quantityTotalSum" class="java.lang.Integer" calculation="Sum">
        <variableExpression><![CDATA[$F{QUANTITY}]]></variableExpression>
        <initialValueExpression><![CDATA[0]]></initialValueExpression>
    </variable>
    <group name="positionNoGroup">
        <groupExpression><![CDATA[$F{POSITIONNO}]]></groupExpression>
        <groupHeader>
            <band height="20">
                <textField>
                    <reportElement x="0" y="0" width="400" height="20"/>
                    <box>
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement textAlignment="Center">
                        <font isBold="true" isItalic="true" isUnderline="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Position no: " + $F{POSITIONNO}]]></textFieldExpression>
                </textField>
            </band>
        </groupHeader>
        <groupFooter>
            <band height="20">
                <textField>
                    <reportElement x="0" y="0" width="400" height="20"/>
                    <textElement>
                        <font isBold="false" isItalic="true" isUnderline="false"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Sum in group: " + $V{quantitySumInGroup}]]></textFieldExpression>
                </textField>
            </band>
        </groupFooter>
    </group>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement x="0" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{DOCUMENTID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="100" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{PRODUCTID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="200" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{QUANTITY}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <lastPageFooter>
        <band height="20">
            <textField>
                <reportElement x="0" y="0" width="400" height="20"/>
                <textElement>
                    <font isBold="true" isItalic="true" isUnderline="false"/>
                </textElement>
                <textFieldExpression><![CDATA["Total sum: " + $V{quantityTotalSum}]]></textFieldExpression>
            </textField>
        </band>
    </lastPageFooter>
</jasperReport>

结果将是:

< img src =https://i.stack.imgur.com/MlNMj.pngalt =iReport预览中的结果>

这篇关于JasperReports的iReport - 产生了一个总计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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