你可以试试这个示例:
<?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):
为了获得 页面上的最后一行 值(蓝色),我使用了默认 evaluationTime 或 evaluationTime 等于 Page 的表达式 值。
为了获得 页面上的第一行值(红色),我使用了具有以下属性的变量 (firstValueOnPage):
resetType:页面
计算:第一
为了显示整个报告的最后一行(绿色)值,我使用了 evaluationTime 等于 报告 值。
我用过iReport 4.8.0。
我添加了按 name 字段排序。无需排序,您将获得相同的数据行为。