【问题标题】:Is it possible to control Jasper Reports field usage in page footer?是否可以在页脚中控制 Jasper Reports 字段的使用?
【发布时间】:2013-04-27 05:34:35
【问题描述】:

我正在尝试添加一个带有简单表达式的文本字段:

$F{foo}

到页脚带。但是,似乎无论我选择什么评估时间,它总是从第一行显示字段 foo 的值。是否可以让它显示 last 行的值?

【问题讨论】:

  • 页面最后一行还是报表最后一行(多页报表)?
  • @cjava:报告的最后一行,与页面无关。
  • @doublep 你用的是什么版本的JR?它对我来说很好(4.8.0)
  • @AlexK:哦,可能是这样。 AFAIR 我们在生产中使用了一个非常旧的(3.5?现在无法检查)版本;在当前的开发中,我们有 5.0。

标签: jasper-reports


【解决方案1】:

你可以试试这个示例:

<?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="show_last_row_in_footer" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="106e6d12-70ca-44b4-a55d-845952f57346">
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="name" class="java.lang.String"/>
    <field name="id" class="java.lang.String"/>
    <sortField name="name"/>
    <variable name="firstValueOnPage" class="java.lang.String" resetType="Page" calculation="First">
        <variableExpression><![CDATA[$F{id}]]></variableExpression>
    </variable>
    <columnHeader>
        <band height="20">
            <staticText>
                <reportElement uuid="5f3d2dfa-b44c-43eb-ac49-aa4ebb81b733" x="0" y="0" width="100" 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"/>
                </textElement>
                <text><![CDATA[Id]]></text>
            </staticText>
            <staticText>
                <reportElement uuid="5f3d2dfa-b44c-43eb-ac49-aa4ebb81b733" x="100" y="0" width="100" 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"/>
                </textElement>
                <text><![CDATA[Name]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="50" splitType="Stretch">
            <textField>
                <reportElement uuid="55abd358-2770-4337-a117-3f8592ce0a34" x="100" y="0" width="100" height="50"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="55abd358-2770-4337-a117-3f8592ce0a34" x="0" y="0" width="100" height="50"/>
                <box leftPadding="10">
                    <topPen lineWidth="1.0"/>
                    <leftPen lineWidth="1.0"/>
                    <bottomPen lineWidth="1.0"/>
                    <rightPen lineWidth="1.0"/>
                </box>
                <textElement/>
                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <pageFooter>
        <band height="43" splitType="Stretch">
            <textField evaluationTime="Page">
                <reportElement uuid="e147d45b-45a3-4749-829f-b648a2c7805f" x="0" y="0" width="163" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA["The last id on page: " + $F{id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="bbf6f99a-c60c-42e9-8147-97b9f3ee4316" x="326" y="0" width="138" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA["The first id on page: " + $V{firstValueOnPage}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement uuid="e147d45b-45a3-4749-829f-b648a2c7805f" x="163" y="0" width="163" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA["The last id for report: " + $F{id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="9ecd61c0-98fa-4282-a0d1-cd8cd325f987" x="435" y="23" width="80" height="20"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement uuid="1c663c4d-1279-447a-91d6-6d03bc53a841" x="515" y="23" width="40" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
</jasperReport>

我已经用这个 CSV 数据源测试了样本

Oslo,45
Berne,22
Boston,32
Chicago,39
Chicago,35
New York,44
Chicago,11
Dallas,47
Oslo,42
Dallas,43
Paris,5
San Francisco,48
Paris,18
Dallas,4
Boston,23
Dallas,0
Dallas,19
Dallas,10
Lyon,38
Lyon,2
Dallas,40
Dallas,36
Dallas,37
Lyon,28
Lyon,17
New York,46
New York,41
Paris,25
San Francisco,7
Berne,9

结果报告的第一页将是(内置于iReport v 4.8.0):

结果报告的最后一页将是(内置于 iReport v 4.8.0):

为了获得 页面上的最后一行 值(蓝色),我使用了默认 evaluationTimeevaluationTime 等于 Page 的表达式 值。

为了获得 页面上的第一行值(红色),我使用了具有以下属性的变量 (firstValueOnPage):
resetType页面
计算第一

为了显示整个报告的最后一行(绿色)值,我使用了 evaluationTime 等于 报告 值。


我用过iReport 4.8.0

我添加了按 name 字段排序。无需排序,您将获得相同的数据行为。

【讨论】:

  • 谢谢,我会在星期一测试这个。
猜你喜欢
  • 1970-01-01
  • 2011-11-14
  • 1970-01-01
  • 2016-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-30
  • 1970-01-01
相关资源
最近更新 更多