JasperReports Subreport Streching(JasperReports Subreport Stretching)

编程入门 行业动态 更新时间:2024-10-28 14:36:44
JasperReports Subreport Streching(JasperReports Subreport Stretching)

我正在尝试使用JasperReports创建一个xls-report。 为此,我使用JasperReports 5.5.0(和相同版本的iReport)和apache poi 3.9。

基础结构是具有子报表的主报表,此子报表还包含另一个子报表。 为了更好地理解一些代码示例:

Masterreport:

<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ada06392-98fc-4512-99d3-a4008c86ed40"> <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/> <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/> <property name="net.sf.jasperreports.export.xls.create.custom.palette" value="true"/> <property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/> <property name="net.sf.jasperreports.export.xls.wrap.text" value="true"/> <property name="net.sf.jasperreports.print.keep.full.text" value="true"/> <property name="ireport.zoom" value="3.1384283767210035"/> <property name="ireport.x" value="34"/> <property name="ireport.y" value="0"/> <parameter name="subreportDisLayer" class="net.sf.jasperreports.engine.JasperReport" isForPrompting="false"/> <field name="nextLayerList" class="java.util.List"/> <field name="field1" class="java.lang.String"/> <field name="field2" class="java.lang.String"/> <background> <band splitType="Stretch"/> </background> <columnHeader> <band height="42" splitType="Stretch"/> </columnHeader> <detail> <band height="13" splitType="Stretch"> <subreport isUsingCache="true" runToBottom="true"> <reportElement x="0" y="0" width="555" height="13" isPrintWhenDetailOverflows="true" uuid="222f19ef-c9f7-40a9-ae44-11ef6e15f1ad"/> <subreportParameter name="subsubreportLayer"> <subreportParameterExpression><![CDATA[$P{subsubreportLayer}]]></subreportParameterExpression> </subreportParameter> <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{nextLayerList})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{subreportLayer}]]></subreportExpression> </subreport> <textField isStretchWithOverflow="true" isBlankWhenNull="true"> <reportElement stretchType="RelativeToTallestObject" mode="Opaque" x="40" y="0" width="30" height="13" isPrintWhenDetailOverflows="true" uuid="ab260763-72ff-47ff-ad53-dfedde447908"/> <box> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> <textElement> <font size="8"/> <paragraph leftIndent="2" tabStopWidth="4"/> </textElement> <textFieldExpression><![CDATA[$F{field1}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true" isBlankWhenNull="true"> <reportElement stretchType="RelativeToTallestObject" mode="Opaque" x="70" y="0" width="50" height="13" isPrintWhenDetailOverflows="true" uuid="c408ac05-ee11-4e49-9609-179429b76e20"/> <box> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> <textElement> <font size="8"/> <paragraph leftIndent="2" tabStopWidth="4"/> </textElement> <textFieldExpression><![CDATA[$F{field2}]]></textFieldExpression> </textField> </band> </detail>

子报告1:

<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="ada06392-98fc-4512-99d3-a4008c86ed40"> <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/> <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/> <property name="net.sf.jasperreports.export.xls.create.custom.palette" value="true"/> <property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/> <property name="net.sf.jasperreports.export.xls.wrap.text" value="true"/> <property name="net.sf.jasperreports.print.keep.full.text" value="true"/> <property name="ireport.zoom" value="3.1384283767210035"/> <property name="ireport.x" value="34"/> <property name="ireport.y" value="0"/> <parameter name="subsubreportLayer" class="net.sf.jasperreports.engine.JasperReport" isForPrompting="false"/> <field name="nextLayerList" class="java.util.List"/> <field name="field3" class="java.lang.String"/> <background> <band splitType="Stretch"/> </background> <detail> <band height="13" splitType="Stretch"> <subreport isUsingCache="true" > <reportElement x="0" y="0" width="555" height="13" isPrintWhenDetailOverflows="true" uuid="222f19ef-c9f7-40a9-ae44-11ef6e15f1ad"/> <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{nextLayerList})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{subsubreportLayer}]]></subreportExpression> </subreport> <textField isStretchWithOverflow="true" isBlankWhenNull="true"> <reportElement stretchType="RelativeToBandHeight" mode="Opaque" x="274" y="0" width="100" height="13" isPrintWhenDetailOverflows="true" uuid="7fae7678-55c7-4308-9977-f71e215b38c9"/> <box> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> <textElement> <font size="8"/> <paragraph leftIndent="2" tabStopWidth="4"/> </textElement> <textFieldExpression><![CDATA[$F{field3}]]></textFieldExpression> </textField> </band> </detail>

第二个子报告看起来和第一个子报告几乎相同。

我的问题是,如果主节点的行高大于子报表的整个带高,子报表将不会将其带高度拉伸到主行高。 我知道它必须只是一个简单的设置组合,但我找不到它。 谢谢你的帮助!

奥利弗

I'm trying to create an xls-report with JasperReports. For that I use JasperReports 5.5.0 (and iReport in the same version) and apache poi 3.9.

The base structure is a master-report with a subreport and this subreport also contains another subreport. For better understanding some code samples:

Masterreport:

<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ada06392-98fc-4512-99d3-a4008c86ed40"> <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/> <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/> <property name="net.sf.jasperreports.export.xls.create.custom.palette" value="true"/> <property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/> <property name="net.sf.jasperreports.export.xls.wrap.text" value="true"/> <property name="net.sf.jasperreports.print.keep.full.text" value="true"/> <property name="ireport.zoom" value="3.1384283767210035"/> <property name="ireport.x" value="34"/> <property name="ireport.y" value="0"/> <parameter name="subreportDisLayer" class="net.sf.jasperreports.engine.JasperReport" isForPrompting="false"/> <field name="nextLayerList" class="java.util.List"/> <field name="field1" class="java.lang.String"/> <field name="field2" class="java.lang.String"/> <background> <band splitType="Stretch"/> </background> <columnHeader> <band height="42" splitType="Stretch"/> </columnHeader> <detail> <band height="13" splitType="Stretch"> <subreport isUsingCache="true" runToBottom="true"> <reportElement x="0" y="0" width="555" height="13" isPrintWhenDetailOverflows="true" uuid="222f19ef-c9f7-40a9-ae44-11ef6e15f1ad"/> <subreportParameter name="subsubreportLayer"> <subreportParameterExpression><![CDATA[$P{subsubreportLayer}]]></subreportParameterExpression> </subreportParameter> <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{nextLayerList})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{subreportLayer}]]></subreportExpression> </subreport> <textField isStretchWithOverflow="true" isBlankWhenNull="true"> <reportElement stretchType="RelativeToTallestObject" mode="Opaque" x="40" y="0" width="30" height="13" isPrintWhenDetailOverflows="true" uuid="ab260763-72ff-47ff-ad53-dfedde447908"/> <box> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> <textElement> <font size="8"/> <paragraph leftIndent="2" tabStopWidth="4"/> </textElement> <textFieldExpression><![CDATA[$F{field1}]]></textFieldExpression> </textField> <textField isStretchWithOverflow="true" isBlankWhenNull="true"> <reportElement stretchType="RelativeToTallestObject" mode="Opaque" x="70" y="0" width="50" height="13" isPrintWhenDetailOverflows="true" uuid="c408ac05-ee11-4e49-9609-179429b76e20"/> <box> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> <textElement> <font size="8"/> <paragraph leftIndent="2" tabStopWidth="4"/> </textElement> <textFieldExpression><![CDATA[$F{field2}]]></textFieldExpression> </textField> </band> </detail>

Subreport 1:

<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="ada06392-98fc-4512-99d3-a4008c86ed40"> <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.rows" value="true"/> <property name="net.sf.jasperreports.export.xls.remove.empty.space.between.columns" value="true"/> <property name="net.sf.jasperreports.export.xls.create.custom.palette" value="true"/> <property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/> <property name="net.sf.jasperreports.export.xls.wrap.text" value="true"/> <property name="net.sf.jasperreports.print.keep.full.text" value="true"/> <property name="ireport.zoom" value="3.1384283767210035"/> <property name="ireport.x" value="34"/> <property name="ireport.y" value="0"/> <parameter name="subsubreportLayer" class="net.sf.jasperreports.engine.JasperReport" isForPrompting="false"/> <field name="nextLayerList" class="java.util.List"/> <field name="field3" class="java.lang.String"/> <background> <band splitType="Stretch"/> </background> <detail> <band height="13" splitType="Stretch"> <subreport isUsingCache="true" > <reportElement x="0" y="0" width="555" height="13" isPrintWhenDetailOverflows="true" uuid="222f19ef-c9f7-40a9-ae44-11ef6e15f1ad"/> <dataSourceExpression><![CDATA[new JRBeanCollectionDataSource($F{nextLayerList})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{subsubreportLayer}]]></subreportExpression> </subreport> <textField isStretchWithOverflow="true" isBlankWhenNull="true"> <reportElement stretchType="RelativeToBandHeight" mode="Opaque" x="274" y="0" width="100" height="13" isPrintWhenDetailOverflows="true" uuid="7fae7678-55c7-4308-9977-f71e215b38c9"/> <box> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> <textElement> <font size="8"/> <paragraph leftIndent="2" tabStopWidth="4"/> </textElement> <textFieldExpression><![CDATA[$F{field3}]]></textFieldExpression> </textField> </band> </detail>

The second subreport looks almost the same like the first one.

My problem is, that if the row height of the master is larger than the whole band height of a subreport, the subreport won't stretch its band height to the masters row height. I know it has to be just a simple combination of settings, but I can't find it.

最满意答案

正如预期的那样,它是一个拉伸选项的简单组合......主报表的元素不能随溢出延伸,但必须将属性net.sf.jasperreports.print.keep.full.text设置为true 。 第一个子报表遵循相同的规则,但第二个子报表的元素必须以溢出方式拉伸。

As expected it was a simple combination of the stretching-option... The elements of the master-report mustn't stretch with overflow, but must have the property net.sf.jasperreports.print.keep.full.text set to true. The first subreport follows the same rule, but the elements of the second subreport must stretch with overflow.

更多推荐

本文发布于:2023-08-04 14:01:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1416410.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Subreport   JasperReports   Stretching   Streching

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!