JasperReports:列表的拉伸行为

时间:2011-10-27 16:22:37

标签: jasper-reports

我在报告中使用了列表组件,在列表之后/下面还有其他报告元素。

List 的底层集合可以包含1到50条记录,所以我不知道在报表设计时列表的大小会有多大,所以我不知道到底在哪里放置以下这些元素。

我正在寻找一种方法,使列表可以像 textField 一样正确拉伸,但 isStretchWithOverflow 属性仅为 textFields 定义,而不是 List 。 目前,对于较大的列表列表与以下报表元素重叠。

有谁知道列表的预期伸展行为是什么?或者我如何解决我的问题?

P.S。我已经在JasperReports forum转发了这个问题,但没有答案:(

这是一个代码示例:

<detail>
    <band height="200">
        <componentElement>
            <reportElement x="0" y="10" width="500" height="100" stretchType="RelativeToBandHeight"/>
            <c:list xmlns:c="http://jasperreports.sourceforge.net/jasperreports/components"
                    xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                <datasetRun subDataset="airfreightRates">
                    <dataSourceExpression>$F{spotAirfreightRates}</dataSourceExpression>
                </datasetRun>

                <c:listContents height="35">
                    <textField isStretchWithOverflow="true" isBlankWhenNull="true">
                        <reportElement x="0" y="0" width="70" height="15"/>
                        <box>
                            <pen lineWidth="1.0" lineColor="#000000"/>
                        </box>
                        <textElement verticalAlignment="Middle">
                            <font fontName="Arial" size="10"/>
                        </textElement>
                        <textFieldExpression class="java.lang.String">
                            "This is very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long textFieldExpression"
                        </textFieldExpression>
                    </textField>
                </c:listContents>
            </c:list>
        </componentElement>
        <staticText>
            <reportElement x="0" y="30" width="500" height="50" positionType="Float" />
            <textElement isStyledText="true"/>
            <text><![CDATA[<font color="#FF0000">Static text outside the list contents!!<b>The placement of the text is the crucial point!!!</b></font>]]></text>
        </staticText>
    </band>
</detail>

2 个答案:

答案 0 :(得分:0)

尝试设置此示例中的属性:

<detail>
    <band height="20" splitType="Stretch">
        <componentElement>
            <reportElement stretchType="RelativeToTallestObject" x="186" y="0" width="57" height="20"/>
            <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                <datasetRun subDataset="dataset1">
                    <datasetParameter name="parameter1">
                        <datasetParameterExpression><![CDATA[$F{PRODUCT_ID}]]></datasetParameterExpression>
                    </datasetParameter>
                    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                </datasetRun>
                <jr:listContents height="20" width="57">
                    <textField isStretchWithOverflow="true">
                        <reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="41" height="10"/>
                        <textElement/>
                        <textFieldExpression><![CDATA[String.valueOf($F{POSITIONS_POSITIONNO}).concat("LONG STRING, very long string ")]]></textFieldExpression>
                    </textField>
                </jr:listContents>
            </jr:list>
        </componentElement>
        <textField isStretchWithOverflow="true">
            <reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{PRODUCT_ID}]]></textFieldExpression>
        </textField>
    </band>
</detail>

我为RelativeToTallestObjectListTextField in List设置了 external TextField 属性并设置了 isStretchWithOverflow external TextField

答案 1 :(得分:0)

请尝试将列表放在后台。

<background>
    <band height="842" splitType="Prevent">
        <frame>
            <reportElement uuid="9020735c-7a94-4807-9596-1aabac997a00" x="28" y="492" width="290" height="14"/>
            <componentElement>
                <reportElement uuid="4259289c-8858-4336-a37b-8ad5a7a1ba51" mode="Transparent" x="0" y="0" width="290" height="14"/>
                <jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
                    <datasetRun subDataset="dataset1" uuid="bf8de899-aa0b-43b4-9f4d-1e999524f66d">
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{inclusions})]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="14" width="290">
                        <textField isStretchWithOverflow="true">
                            <reportElement uuid="f8997d71-b315-4be6-9bdf-c3d0c20d0424" positionType="Float" stretchType="RelativeToTallestObject" x="14" y="3" width="271" height="8" isPrintWhenDetailOverflows="true" forecolor="#4A4A49"/>
                            <textElement>
                                <font fontName="Avenir-Medium" size="11" isBold="false"/>
                                <paragraph lineSpacing="Proportional" lineSpacingSize="1.03"/>
                            </textElement>
                            <textFieldExpression><![CDATA[$F{inclusion}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>
        </frame>
    </band>