您好我是Jasper报告的新手,我正在报告一个文本字段和相应的子报告在详细信息带下的框架中。现在我需要应用拆分类型以防止细节带,但我无法&# 39;因为我在细节范围内有子报告。请在此帮助我。谢谢。
<detail>
<band height="30">
<frame>
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="500" height="30" backcolor="#333333"/>
<box>
<topPen lineWidth="0.5" lineStyle="Solid" lineColor="#9B64C8"/>
<leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#9B64C8"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#9B64C8"/>
</box>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" mode="Opaque" x="0" y="0" width="166" height="30" isPrintInFirstWholeBand="true" isPrintWhenDetailOverflows="true" forecolor="#000000" backcolor="#FFFFFF">
</reportElement>
<box leftPadding="5">
<topPen lineWidth="0.5" lineStyle="Solid" lineColor="#9BA66D"/>
<leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#9BA66D"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#9BA66D"/>
<rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#9BA66D"/>
</box>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font fontName="Helvetica" size="9" isBold="false" pdfFontName="Helvetica" pdfEncoding="CP1252" isPdfEmbedded="false"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{text1}]]></textFieldExpression>
</textField>
<subreport>
<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="0" height="30"/>
<dataSourceExpression><![CDATA[$F{subreport}]]></dataSourceExpression>
<subreportExpression class="java.lang.String"><![CDATA["sub.jasper"]]></subreportExpression>
</subreport>
</frame>
</band>
</detail>
答案 0 :(得分:1)
由于textField
需要 subreport
旁边,您需要jasper报告才能尝试在1页上完整地打印记录。
<subreport>
<reportElement stretchType="RelativeToTallestObject" x="166" y="0" width="334" height="30" uuid="e812a308-674c-41dc-be83-e872752c8d6d"/>
<dataSourceExpression><![CDATA[$F{subreport}]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{absolutePath} + "sub.jasper"]]></subreportExpression>
</subreport>
子报表应具有正确的pageWidth,columnWidth和margin
<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" pageWidth="334" pageHeight="842" columnWidth="332" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="775a7e35-9af8-4206-a155-b05a478c35b0">
splitType="prevent"
从子报表移至主报表。这将需要您的数据源是JRRewindableDataSource,因为jasper报告将尝试填充当前页面中的band,但如果它不能,则需要倒回并填写下一页。您需要在数据源中实现moveFirst()
方法。