Jasper报告拆分类型 [英] Jasper report split type

查看:93
本文介绍了Jasper报告拆分类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jasper报告将报告导出到Word文档.在详细信息部分,我有子报告.我对频段拆分类型有疑问.当我选择拆分类型 stretch 立即时,出现以下问题.

I am using jasper report to export my reports to word document. On the detail section I have sub report. I have a problem with band split type. When I choose split type stretch or immediate I got the below problem.

当我选择 Prevent 拆分类型时,我没有收到此错误,但是如果行空间超过了保留的带高,这一次在页面底部会有很多空白.如何在页面底部部分分割数据而不会出现边框布局错误?

When I choose Prevent split type I don't get this error but this time there are lots of white space at the bottom of page if row space more than remain band height. How can I split my data partially at the bottom of page without border layout error?

示例代码.只需复制并粘贴任何jasper studio编辑器,并在出现提示时输入长文本(至少填充两页)即可.

sample code. just copy and paste any jasper studio editor and enter long text(at least fill two page) when prompting.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.0.final using JasperReports Library version 6.3.0  -->
<!-- 2016-09-27T22:00:51 -->
<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="Test" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f86bcfb7-d774-451f-9f46-c58f57e0efbb">
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <parameter name="Parameter1" class="java.lang.String"/>
    <queryString>
        <![CDATA[select * from dummy]]>
    </queryString>
    <field name="sno" class="java.lang.Integer"/>
    <field name="filed1" class="java.lang.Integer"/>
    <field name="filed2" class="java.lang.String"/>
    <columnHeader>
        <band height="30">
            <staticText>
                <reportElement x="0" y="0" width="120" height="30" uuid="0cd17b54-755c-42fe-9363-7266a24337e3"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <text><![CDATA[Static Text]]></text>
            </staticText>
            <staticText>
                <reportElement x="170" y="0" width="130" height="30" uuid="f216b782-3080-4ba8-8cc3-2609c684f4be"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <text><![CDATA[filed1]]></text>
            </staticText>
            <staticText>
                <reportElement x="300" y="0" width="90" height="30" uuid="71985024-8b9a-49ae-81e0-6d6e9335cec7"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <text><![CDATA[filed2]]></text>
            </staticText>
            <staticText>
                <reportElement x="120" y="0" width="50" height="30" uuid="d45c0977-d842-424b-ab44-7edd5672b72d"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <text><![CDATA[Image]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="30">
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="120" height="30" isPrintWhenDetailOverflows="true" uuid="fb93f1ac-7f7a-48fe-afa7-4aab5370cbec"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textFieldExpression><![CDATA[""]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="170" y="0" width="130" height="30" uuid="b5a72533-c1b6-4af9-a0b7-06d099981190"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textFieldExpression><![CDATA[$F{filed1}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="300" y="0" width="90" height="30" isPrintWhenDetailOverflows="true" uuid="bab5a3e9-22db-46b0-9302-f7614a6f6add"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textFieldExpression><![CDATA[$P{Parameter1}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="120" height="30" isPrintWhenDetailOverflows="true" uuid="d4338fad-1803-491e-90ef-8e01cb3de80d"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textFieldExpression><![CDATA["Hello"]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="170" y="0" width="130" height="30" isPrintWhenDetailOverflows="true" uuid="8cdac468-0a3f-4ed3-844b-473e1371f92e"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textFieldExpression><![CDATA[""]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true">
                <reportElement positionType="Float" stretchType="RelativeToTallestObject" x="120" y="0" width="50" height="30" isPrintWhenDetailOverflows="true" uuid="6ab2f4f8-04cd-4a6f-b945-3a7af4b8c3fa"/>
                <box>
                    <topPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <leftPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <bottomPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                    <rightPen lineWidth="0.5" lineStyle="Solid" lineColor="#000000"/>
                </box>
                <textFieldExpression><![CDATA["Hello"]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

最终解决了.感谢@ dada67提供详细答案.

Finally solution solved. Thanks @dada67 for detail answer.

解决方案1: 您可以在类路径上创建jasperreports.properties文件,并将以下行添加到该文件中:

Solution 1: you can create jasperreports.properties file on your classpath and add the below line to this file:

net.sf.jasperreports.consume.space.on.overflow=falsenet.sf.jasperreports.consume.space.on.overflow=false

解决方案2: 您还可以通过编程方式设置该值

Solution 2: you can set this value programmatically also

DefaultJasperReportsContext djrc = net.sf.jasperreports.engine.DefaultJasperReportsContext.getI‌​nstance();
djrc.setProperty(net.sf.jaspe‌​rreports.engine.fill‌​.JRFillTextElement.P‌​ROPERTY_CONSUME_SPAC‌​E_ON_OVERFLOW,
                    Boolean.toString(false));

推荐答案

您描述的问题似乎与根据评论,即将发布的版本(6.3.1)将解决此问题.

According to the comments, the upcoming release (6.3.1) will fix the issue.

同时,您可以在jasperreports.properties中设置以下属性来避免该问题:

In the meantime you can set the following property in your jasperreports.properties to avoid the problem:

net.sf.jasperreports.consume.space.on.overflow=false

这篇关于Jasper报告拆分类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆