【问题标题】:Background on sub-report does not display子报告的背景不显示
【发布时间】:2013-09-07 11:31:28
【问题描述】:

我正在使用 iReport 4.5.1(不幸的是,不能使用更高版本)并且有一个关联了多个子报告的报告。在主报告的 Background 带中,我放置了用作水印的文本 - 这在每个报告页面上都可以正常显示。在一个子报告中,我想显示一个额外的水印,因此在此报告的背景带中添加了一个额外的文本字段元素。

当我整体运行报表时,子报表的水印文本不显示,但是当我单独运行子报表时,其水印文本显示正常。任何想法为什么会发生这种情况?

【问题讨论】:

    标签: background jasper-reports watermark subreport


    【解决方案1】:

    您可以查看此示例。

    主报告设计(在iReport中):

    我在 Background 波段上放置了 4 个 staticText

    主报告jrxml文件是:

    <?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="mainrep_watermark" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ffeb1237-be4e-4cca-8a63-223aa5d8f3e6">
        <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
            <defaultValueExpression><![CDATA["/somepath"]]></defaultValueExpression>
        </parameter>
        <queryString>
            <![CDATA[SELECT * FROM product ORDER BY id]]>
        </queryString>
        <field name="ID" class="java.lang.Integer"/>
        <field name="NAME" class="java.lang.String"/>
        <field name="COST" class="java.math.BigDecimal"/>
        <group name="idgroup">
            <groupExpression><![CDATA[$F{ID}]]></groupExpression>
            <groupFooter>
                <band height="28">
                    <subreport>
                        <reportElement uuid="710fe82b-fd08-4db3-bba1-929870f83fa4" x="100" y="0" width="200" height="27"/>
                        <subreportParameter name="productId">
                            <subreportParameterExpression><![CDATA[$F{ID}]]></subreportParameterExpression>
                        </subreportParameter>
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                        <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "subreport_watermark.jasper"]]></subreportExpression>
                    </subreport>
                </band>
            </groupFooter>
        </group>
        <background>
            <band height="802" splitType="Stretch">
                <staticText>
                    <reportElement uuid="0e7c3a54-8876-4523-9bad-2b582b1defb9" x="51" y="15" width="468" height="148" forecolor="#0033FF"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                        <font size="48"/>
                    </textElement>
                    <text><![CDATA[Master watermark 1]]></text>
                </staticText>
                <staticText>
                    <reportElement uuid="584b9b65-c040-43a0-96ce-6fa14e9db597" x="51" y="174" width="468" height="148" forecolor="#0033FF"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                        <font size="48"/>
                    </textElement>
                    <text><![CDATA[Master watermark 2]]></text>
                </staticText>
                <staticText>
                    <reportElement uuid="4f4f55b5-cbd4-4b10-bcf4-1e81d16bb537" x="51" y="344" width="468" height="148" forecolor="#0033FF"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                        <font size="48"/>
                    </textElement>
                    <text><![CDATA[Master watermark 3]]></text>
                </staticText>
                <staticText>
                    <reportElement uuid="10b1534f-d880-4ca3-9a2f-847d68826011" x="51" y="524" width="468" height="148" forecolor="#0033FF"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
                        <font size="48"/>
                    </textElement>
                    <text><![CDATA[Master watermark 4]]></text>
                </staticText>
            </band>
        </background>
        <columnHeader>
            <band height="20" splitType="Stretch">
                <staticText>
                    <reportElement uuid="d337add8-2a0d-4a9e-ad3c-3dfb322b715a" mode="Opaque" x="0" y="0" width="100" height="20" backcolor="#CCCCCC"/>
                    <box>
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font isBold="true" isItalic="true"/>
                    </textElement>
                    <text><![CDATA[Id]]></text>
                </staticText>
                <staticText>
                    <reportElement uuid="97ff3089-7082-4f30-850e-e59836ff48a2" mode="Opaque" x="100" y="0" width="100" height="20" backcolor="#CCCCCC"/>
                    <box>
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font isBold="true" isItalic="true"/>
                    </textElement>
                    <text><![CDATA[Name]]></text>
                </staticText>
                <staticText>
                    <reportElement uuid="ec4bc628-f6bb-40be-9e46-fd49327071f2" mode="Opaque" x="200" y="0" width="100" height="20" backcolor="#CCCCCC"/>
                    <box>
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement textAlignment="Center" verticalAlignment="Middle">
                        <font isBold="true" isItalic="true"/>
                    </textElement>
                    <text><![CDATA[Cost]]></text>
                </staticText>
            </band>
        </columnHeader>
        <detail>
            <band height="20" splitType="Stretch">
                <textField>
                    <reportElement uuid="2b43cdac-3453-499e-a6e0-b33eef8bf3f9" x="0" y="0" width="100" height="20"/>
                    <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>
                <textField>
                    <reportElement uuid="75ba99d4-646e-470c-b68b-fa111b702ac7" x="100" y="0" width="100" height="20"/>
                    <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="451db60d-5255-41fe-b5fe-8e523118fab3" x="200" y="0" width="100" height="20"/>
                    <box leftPadding="10">
                        <topPen lineWidth="1.0"/>
                        <leftPen lineWidth="1.0"/>
                        <bottomPen lineWidth="1.0"/>
                        <rightPen lineWidth="1.0"/>
                    </box>
                    <textElement/>
                    <textFieldExpression><![CDATA[$F{COST}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
    </jasperReport>
    

    子报表的设计是(在iReport中):

    我在 Background 带上放置了一个 staticText 并将文本旋转 90 度。

    subreportjrxml文件是:

    <?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="subreport_watermark" language="groovy" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="cf5d8eca-6c3a-4e1f-a6c9-107436e0ac48">
        <parameter name="productId" class="java.lang.String"/>
        <queryString language="SQL">
            <![CDATA[SELECT TOP 10 QUANTITY, PRICE FROM positions WHERE productid=$P{productId}]]>
        </queryString>
        <field name="QUANTITY" class="java.lang.Integer"/>
        <field name="PRICE" class="java.math.BigDecimal"/>
        <background>
            <band height="95" splitType="Stretch">
                <staticText>
                    <reportElement uuid="f09a53bb-3b62-4e97-8e6b-2c592f469c3d" positionType="Float" stretchType="RelativeToBandHeight" x="78" y="0" width="100" height="95" forecolor="#FF3333"/>
                    <textElement textAlignment="Center" verticalAlignment="Middle" rotation="Left">
                        <font size="20"/>
                    </textElement>
                    <text><![CDATA[Subreport watermark]]></text>
                </staticText>
            </band>
        </background>
        <detail>
            <band height="15" splitType="Stretch">
                <textField>
                    <reportElement uuid="135d5748-db78-4272-a1c8-a94f5ce5549e" x="43" y="0" width="60" height="15"/>
                    <box leftPadding="10">
                        <topPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                        <leftPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                        <bottomPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                        <rightPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                    </box>
                    <textElement>
                        <font size="8"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Quantity: " + $F{QUANTITY}]]></textFieldExpression>
                </textField>
                <textField>
                    <reportElement uuid="8736b7b8-b7cd-4fd5-8494-9519cb55317c" x="103" y="0" width="60" height="15"/>
                    <box leftPadding="10">
                        <topPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                        <leftPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                        <bottomPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                        <rightPen lineWidth="0.25" lineStyle="Dashed" lineColor="#3300FF"/>
                    </box>
                    <textElement>
                        <font size="8"/>
                    </textElement>
                    <textFieldExpression><![CDATA["Price: " + $F{PRICE}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
    </jasperReport>
    

    结果将是(在Adobe Reader中生成pdf):

    【讨论】:

      【解决方案2】:

      感谢 Alex K。我发现我的问题实际上是由于在我的主报告中定义了页眉。由于某种原因,这似乎覆盖了子报告显示的背景带。我不知道为什么,并且很想知道是否有人知道原因。我可以通过从主报告中删除页眉来解决我的问题。 (user2756852/Deb)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-08-22
        • 1970-01-01
        相关资源
        最近更新 更多