在Jasper报告中添加字段

时间:2015-08-14 08:02:06

标签: jasper-reports

所以我正在编辑我们系统中的旧Jasper文档。该文档提供了基于XML文件的装箱单。

现在我们想做以下事情:

如果同一篇文章的文章行超过1条,我们希望将它们添加/组合成一行。

我对iReport不太熟悉,我只做了一些小字段链接更改。

当我查看文档的Xml时,我发现你可以在包含一些代码的文本字段上使用表达式。我想我需要为表示文章行的组编写一些代码吗?

以下是文章行的xml部分:

<detail>
        <band height="38" splitType="Stretch">
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="textField-19_1" style="column_field_small" x="228" y="2" width="264" height="12" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{articleDescription}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="textField-20_2" style="column_field_small" x="5" y="2" width="222" height="12" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{articleCode}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="staticText-31_5" style="sub_column_header_small" x="229" y="14" width="39" height="12"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression class="java.lang.String"><![CDATA[$R{CWjp.Quantity}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="staticText-32_6" style="sub_column_header_small" x="272" y="14" width="24" height="12"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$R{CWjp.Pack}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="staticText-33_7" style="sub_column_header_small" x="415" y="14" width="52" height="12"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression class="java.lang.String"><![CDATA[$R{CWjp.Grossweight}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="staticText-34_8" style="sub_column_header_small" x="469" y="14" width="61" height="12"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression class="java.lang.String"><![CDATA[$R{CWjp.Nettweight}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
                <reportElement key="textField-21_3" style="sub_column_field_small" x="490" y="26" width="40" height="12"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression class="java.lang.Double"><![CDATA[$F{finalNetWeight}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
                <reportElement key="textField-22_4" style="sub_column_field_small" x="427" y="26" width="40" height="12"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression class="java.lang.Double"><![CDATA[$F{finalGrossWeight}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="textField-23_5" style="sub_column_field_small" x="272" y="26" width="24" height="12"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{finalPackageCode}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" pattern="###0" isBlankWhenNull="true">
                <reportElement key="textField-24_6" style="sub_column_field_small" x="228" y="26" width="40" height="12"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression class="java.lang.Double"><![CDATA[$F{finalQuantity}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="textField-23_5" style="sub_column_field_small" x="300" y="26" width="80" height="12"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[( $F{serialCode} != null && $F{serialCode}.length() > 0 ? $F{serialCode} :
( $F{customersPalletCode} != null && $F{customersPalletCode}.length() > 0 ? $F{customersPalletCode} :
( $F{lotCode} != null && $F{lotCode}.length() > 0 ? $F{lotCode} : "" )) )]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="staticText-32_6" style="sub_column_header_small" x="300" y="14" width="80" height="12">
                    <printWhenExpression><![CDATA[new Boolean(1==2)]]></printWhenExpression>
                </reportElement>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA[$R{CWjp.SerPltLotCode}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                <reportElement key="staticText-32_6" style="sub_column_header_small" x="380" y="26" width="43" height="12"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA["(" + ( $F{serialCode} != null && $F{serialCode}.length() > 0 ? $R{CWjp.Serial} :
( $F{customersPalletCode} != null && $F{customersPalletCode}.length() > 0 ? $R{CWjp.Pallet} :
( $F{lotCode} != null && $F{lotCode}.length() > 0 ? $R{CWjp.Lot1} : "" )) )
+ ")"]]></textFieldExpression>
            </textField>
        </band>
    </detail>

1 个答案:

答案 0 :(得分:0)

这听起来像是Groups的工作。请记住,在应用分组之前必须对数据进行排序。