4

在这个例子中子报表重叠——我做错了什么?第二个应该“浮动”在第一个之下,它的 'y' 属性被忽略,但事实并非如此。

谢谢 !!

<?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="report name" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["C:\\reportFolder\\"]]></defaultValueExpression>
    </parameter>
    <background>
        <band/>
    </background>
    <detail>
        <band height="200">
            <subreport>
                <reportElement positionType="FixRelativeToTop" x="19" y="0" width="200" height="50"/>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
                <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "report1.jasper"]]></subreportExpression>
            </subreport>
            <subreport>
                <reportElement positionType="Float" mode="Transparent" x="19" y="20" width="200" height="50" backcolor="#FFFF66"/>
                <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
                <subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "report1.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
</jasperReport>
4

2 回答 2

13

I got the answer! (I'm the one who asked, different IP I guess) According to the documentation, the floating element would have its y attribute ignored. I had taken that literally, tried arbitrary values for y and saw that everytime the element was placed at the specified position.

But no, you need to set y to position the element right below the previous one, according to that element's declared y and height, even though its actual height could be stretched when filled with data. In my sample code, the second subreport should have had y="50".

Furthermore, I see that the declared height of an element is taken as a minimum height. If the actual subreport is shorter than the height, the enclosing element won't be shrunk, so it would be a good idea to set the minimum expected height for elements that could be stretched.

于 2008-12-11T11:54:07.873 回答
2

你是对的,但你需要更多。您需要从子报表中删除边距。

  • 从菜单 -> 格式 -> 从菜单中删除报表边距

  • 格式 -> 页面格式 -> 使页边距为 0

于 2012-10-05T07:20:10.780 回答