获取Jasper Reports表

时间:2015-12-01 00:24:08

标签: jasper-reports

我在Eclipse中使用JasperSoft Studio为教会生成注册表。页眉标题包含页面上的姓氏。因此,如果页面以A开头,则页面1将具有A-D,并以D结尾。enter image description here

对于如此简单的任务而言,这变得非常复杂。我只想阅读last_name字段在每个页面的第一行和最后一行中的内容,取出它的第一个字母,然后将其粘贴在标题中。

欢迎任何想法,我很难过。

2 个答案:

答案 0 :(得分:2)

要获取页面中字段的第一个和最后一个值,请使用变量 resetType ,并在{上设置正确的 evalutationTime {1}}(您需要使用2个textField将它们正确地对齐)

此示例将说明如何在每个页面

上获取字段textField第一个最后值>

页面中字段的第一个值

变量上的 resetType 将为$F{Last_Name}

resetType="None"

并在<variable name="firstValueOnPage" class="java.lang.String" resetType="None"> <variableExpression><![CDATA[$F{Last_Name}]]></variableExpression> </variable> 中,将变量与textField一起使用(默认情况下不需要标记)

evalution="Now"

页面中字段的最后一个值

变量的 resetType <textField> <reportElement x="30" y="19" width="100" height="20" uuid="e6421031-6db7-4fd9-995f-94cef2eb3621"/> <textFieldExpression><![CDATA[$V{firstValueOnPage}]]></textFieldExpression> </textField>

resetType="Page"

并在textField中使用变量<variable name="lastValueOnPage" class="java.lang.String" resetType="Page"> <variableExpression><![CDATA[$F{Last_Name}]]></variableExpression> </variable>

evaluationTime="Page"

要获得第一个和最后一个值的第一个字符,我看到你已经弄明白了,但是为了完成答案,textFieldExpression将是

<textField evaluationTime="Page">
    <reportElement x="170" y="19" width="100" height="20" uuid="9100baa5-0095-4dc3-ac79-2cd87562a92d"/>
    <textFieldExpression><![CDATA[$V{lastValueOnPage}]]></textFieldExpression>
</textField>

现在只需将两个textField放在一起(正确对齐),就可以获得所需的结果。

了解有关 resetType evalutationTime (来自jasper report api 6.2.0)的更多信息的其他信息

<强> resetType

  

- 在迭代过程中,通过数据源,变量随每条记录递增   报告 - 在报告填写过程中,变量永远不会增加   页面 - 每个新页面都会增加变量    - 每个新列都会增加变量    - 每次incrementGroup属性指定的组中断

时,变量都会递增

<强> EvalutationTime

  

自动评估时间,表示参与的每个变量   表达式应在发动机决定的时间进行评估   乐队元素将在乐队结束时进行评估   一个常量,指定在填充每列后应计算表达式。   一个常量,指定在每次分组后应评估表达式   用于主报告结束时评估的元素   现在一个常量,指定表达式应在填充过程中的恰好时刻进行评估。
  页面一个常量,指定在填充每个页面后应评估表达式。
  报告一个常量,指定应在填充过程结束时评估表达式。

答案 1 :(得分:1)

报告按Last_Name排序,因此我们可以使用计算最低和最高

定义变量:

<variable name="lowestFirstLetter" class="java.lang.String" resetType="Page" calculation="Lowest">
    <variableExpression><![CDATA[$F{Last_Name}.substring(0,1)]]></variableExpression>
</variable>
<variable name="highestFirstLetter" class="java.lang.String" resetType="Page" calculation="Highest">
    <variableExpression><![CDATA[$F{Last_Name}.substring(0,1)]]></variableExpression>
</variable>

并将带有evaluationTime="Page"的textFields放入PageHeader band

<pageHeader>
    <band height="35" splitType="Stretch">
        <textField evaluationTime="Page">
            <reportElement x="80" y="15" width="100" height="20" uuid="72af3431-eb3d-4f40-993b-4f0733e779cd"/>
            <textFieldExpression><![CDATA[$V{lowestFirstLetter}]]></textFieldExpression>
        </textField>
        <textField evaluationTime="Page">
            <reportElement x="260" y="15" width="150" height="20" uuid="0452517b-5066-4f8a-af6b-f941f1d3c1cb"/>
            <textFieldExpression><![CDATA[$V{highestFirstLetter}]]></textFieldExpression>
        </textField>
    </band>
</pageHeader>
祝你好运

相关问题