2013-10-31 103 views
0

我想用JasperReports創建一個xls報表。 爲此我使用JasperReports 5.5.0(和iReport在同一版本)和apache poi 3.9。JasperReports子報表Streching

基本結構是帶有子報表的主報表,此子報表還包含另一個子報表。爲了更好地理解一些代碼示例:

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> 

第二報表看起來幾乎同樣喜歡第一個。

我的問題是,如果主人的行高度大於子報表的整個樂隊高度,則子報表不會將其樂隊高度伸展到主人行高度。 我知道它只是一個簡單的設置組合,但我找不到它。 感謝您的幫助!

奧利弗

回答

0

正如預期的那樣是拉伸選項的簡單組合... 主報告的內容不得與溢出伸展,但必須具備的使用性能net.sf.jasperreports .print.keep.full.text設置爲true。 第一個子報表遵循相同的規則,但第二個子報表的元素必須延伸並溢出。

相關問題