打印表达式时仅打印组中的最后一个元素 [英] Print When Expression to print only the last element in the group

查看:79
本文介绍了打印表达式时仅打印组中的最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在oracle表中有以下数据集,并希望从该数据生成CSV文件。

I have following data set in oracle table and want to generate CSV file from that data.


CaseID  Amount
1000     10
1000     20
1000     50      
2000     30 
2000     10     
3000     30 
3000     20 
3000     20   

有必要从上面的数据中显示以下输出。

It is necessary to show the following output from above data.


CaseID  Amount  Aggregate
1000     10
1000     20
1000     50      80

2000     30 
2000     10      40

3000     30 
3000     20 
3000     20      70

通过累积根据caseID组的金额总和来填充汇总列。

Aggregate column is populated by accumulating the sum of Amount according to caseID group.

组摘要应显示在组的最后一个元素上。但不是在下一行,应该显示在同一行和下一列中,与最后一个元素匹配。

Group summary should display on last element of the group. But not in the next row, should display in the same row and next column, that matching with the last element.

我尝试使用'Print When Expression'用于其他方案,但无法使用此方案。我也发现了类似的问题,但不满足这个要求。所以想知道可能的解决方案。

I tried with 'Print When Expression' for other scenarios, but unable to use with this scenario. Also I have find similar questions, but not cater with this requirement. So would like to know the possible solutions for this.

推荐答案

你可以用evaluateTime =Auto做类似的事情。您可以使用文本元素显示组中最后一条记录的值,对于其他记录则为空。它根本不打印元素,但是你不能在表达式时使用print,因为它没有延迟评估。

You can do something similar with evaluationTime="Auto". You can have a text element that shows the value on the last record in the group and is empty for other records. It's not the same as not printing the element at all, but you can't use the print when expression because it doesn't have delayed evaluation.

evaluationTime =Auto 使用重置类型的变量来决定它读取变量值的时刻。每个组都有一个自动创建的计数变量,该变量随组重置,如果您创建一个重置每个记录的新变量,您可以使用它来确定当前记录是否是该组中的最后一个记录。

evaluationTime="Auto" uses the reset types of variables to decide the moment at which it reads the variable values. Each group has an automatically created count variable that resets with the group, and if you create a new variable that resets on each record you can use it to determine if the current record is the last record in the group.

整个报告看起来像这样

<?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="report" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" resourceBundle="jasperreports" whenResourceMissingType="Key" isIgnorePagination="true" uuid="816687ff-bb19-4f6b-a2b6-53634ce095fc">
    <style name="dd" isDefault="true" fontSize="10"/>
    <field name="CaseID" class="java.lang.Integer"/>
    <field name="Amount" class="java.lang.Integer"/>
    <variable name="AmountSum" class="java.lang.Integer" resetType="Group" resetGroup="CaseIDGroup" calculation="Sum">
        <variableExpression><![CDATA[$F{Amount}]]></variableExpression>
    </variable>
    <variable name="GroupCurrentCount" class="java.lang.Integer" resetType="None">
        <variableExpression><![CDATA[$V{CaseIDGroup_COUNT}]]></variableExpression>
    </variable>
    <group name="CaseIDGroup">
        <groupExpression><![CDATA[$F{CaseID}]]></groupExpression>
    </group>
    <detail>
        <band height="20">
            <textField>
                <reportElement x="0" y="0" width="100" height="20" uuid="af7a5ea9-ffcb-4a7f-aaa8-7d5cab06a579"/>
                <textFieldExpression><![CDATA[$F{CaseID}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="100" y="0" width="100" height="20" uuid="a7e2795e-456a-4c6e-946f-8315df453b1f"/>
                <textFieldExpression><![CDATA[$F{Amount}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Auto" isBlankWhenNull="true">
                <reportElement x="200" y="0" width="100" height="20" uuid="afda4fcc-78fc-46f9-8c5c-2e0c4f04dfa5"/>
                <textFieldExpression><![CDATA[$V{GroupCurrentCount}.equals($V{CaseIDGroup_COUNT}) ? $V{AmountSum} : null]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

这篇关于打印表达式时仅打印组中的最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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