2012-01-31 4 views
4

異なるページにまたがる連絡先を含むレポートを生成しています。JasperReports:フィールドが次のページにプッシュされているかどうかを確認する方法

以前は、isSplitAllowedを「true」に設定しました。 しかし、連絡先が別のページに分割されることは望ましくありません。 私はそれを「偽」に設定しました。レポートのレイアウトははるかに良く見えました。しかし、新しい問題が発生しました。

私の見出しには、最初の人物とそのページの最後の人物の名前が印刷されています。 コンタクトが次のページにプッシュされると、コンタクトは現在のページで処理されます。 ボブが最初のページの一番下にあるはずだったとします。しかし、それが分割されないように、Bobは2番目のページの最初の要素になりました。 しかし、私の最初のページのヘッダーにはまだアリス...ボブ(アリスが最初のページの最初の人です)があります。 そして私の2番目のページにはまだブレンダ...ダグ(ブレンダは2ページ目の2人目、そしてダグは2ページ目の最後の人です)。

ヘッダにマイ出力 [$ V {pageFirstItem} + "..." + $のV {pageLastItem}]]>

pageFirstItemがである:

<variable name="pageFirstItem" class="java.lang.String" resetType="Page" calculation="First"> 
     <variableExpression><![CDATA[$F{lastName}]]></variableExpression> 
     <initialValueExpression><![CDATA[$F{lastName}]]></initialValueExpression> 
    </variable> 

とpageLastItemであります:

<variable name="pageLastItem" class="java.lang.String" resetType="Report" calculation="Nothing"> 
    <variableExpression><![CDATA[$F{lastName}]]></variableExpression> 

答えて

1

私は、iReport 3.0.5に基づいて、以下に動作するサンプル回避策を添付しました。 isSplitAllowedを有効または無効にして実行してテストすることができます。問題は、isSplitAllowed="false"がレコードをページi + 1に印刷する場合でも、詳細レコードがページiで処理されることです。

概要:firstItemについては

  1. 、何の計算は必要ありません。ヘッダーに名前フィールドを入力するだけです。
  2. lastItemの場合、変数propjava.util.Propertyの変数を使用して処理された名前を保存する必要があります。これは、ダミーの高さ0、textFieldをdetailセクションに入れ、次の値prop.setProperty("lastSavedName", $F{Name})で行います。このtextFieldは、名前が印刷された後で保存されることを保証します。
  3. 次に、というヘッダーに、prop.getProperty("lastSavedName")という小文字の値を入れます。

    <?xml version="1.0" encoding="UTF-8" ?> 
    <!-- Created with iReport - A designer for JasperReports --> 
    <!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"> 
    <jasperReport 
         name="Untitled_report_1" 
         columnCount="1" 
         printOrder="Vertical" 
         orientation="Portrait" 
         pageWidth="595" 
         pageHeight="842" 
         columnWidth="535" 
         columnSpacing="0" 
         leftMargin="30" 
         rightMargin="30" 
         topMargin="20" 
         bottomMargin="20" 
         whenNoDataType="NoPages" 
         isFloatColumnFooter="true" 
         isTitleNewPage="false" 
         isSummaryNewPage="true"> 
        <property name="ireport.zoom" value="1.0" /> 
        <property name="ireport.x" value="0" /> 
        <property name="ireport.y" value="0" /> 
        <property name="ireport.scriptlethandling" value="0" /> 
        <property name="ireport.encoding" value="UTF-8" /> 
        <import value="java.util.*" /> 
        <import value="net.sf.jasperreports.engine.*" /> 
        <import value="net.sf.jasperreports.engine.data.*" /> 
    
        <queryString><![CDATA[select 1 as id, 'Name 1' as name from dual union all 
    select 2 as id, 'Name 2' as name from dual union all 
    select 3 as id, 'Name 3' as name from dual union all 
    select 4 as id, 'Name 4' as name from dual union all 
    select 5 as id, 'Name 5' as name from dual union all 
    select 6 as id, 'Name 6' as name from dual union all 
    select 7 as id, 'Name 7' as name from dual union all 
    select 8 as id, 'Name 8' as name from dual union all 
    select 9 as id, 'Name 9' as name from dual union all 
    select 10 as id, 'Name 10' as name from dual union all 
    select 11 as id, 'Name 11' as name from dual union all 
    select 12 as id, 'Name 12' as name from dual union all 
    select 13 as id, 'Name 13' as name from dual union all 
    select 14 as id, 'Name 14' as name from dual union all 
    select 15 as id, 'Name 15' as name from dual union all 
    select 16 as id, 'Name 16' as name from dual union all 
    select 17 as id, 'Name 17' as name from dual union all 
    select 18 as id, 'Name 18' as name from dual union all 
    select 19 as id, 'Name 19' as name from dual union all 
    select 20 as id, 'Name 20' as name from dual union all 
    select 21 as id, 'Name 21' as name from dual union all 
    select 22 as id, 'Name 22' as name from dual union all 
    select 23 as id, 'Name 23' as name from dual union all 
    select 24 as id, 'Name 24' as name from dual union all 
    select 25 as id, 'Name 25' as name from dual union all 
    select 26 as id, 'Name 26' as name from dual union all 
    select 27 as id, 'Name 27' as name from dual union all 
    select 28 as id, 'Name 28' as name from dual]]></queryString> 
    
        <field name="ID" class="java.math.BigDecimal"/> 
        <field name="NAME" class="java.lang.String"/> 
    
        <variable name="prop" class="java.util.Properties" resetType="Report" calculation="System"> 
         <initialValueExpression><![CDATA[new Properties()]]></initialValueExpression> 
        </variable> 
         <background> 
          <band height="0" isSplitAllowed="true" > 
          </band> 
         </background> 
         <title> 
          <band height="0" isSplitAllowed="true" > 
          </band> 
         </title> 
         <pageHeader> 
          <band height="16" isSplitAllowed="true" > 
           <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > 
            <reportElement 
             x="0" 
             y="0" 
             width="96" 
             height="16" 
             key="textField-3"/> 
            <box></box> 
            <textElement> 
             <font/> 
            </textElement> 
           <textFieldExpression class="java.lang.String"><![CDATA["First " + $F{ID}]]></textFieldExpression> 
           </textField> 
           <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Page" hyperlinkType="None" hyperlinkTarget="Self" > 
            <reportElement 
             x="96" 
             y="0" 
             width="100" 
             height="16" 
             key="textField-4"/> 
            <box></box> 
            <textElement> 
             <font/> 
            </textElement> 
           <textFieldExpression class="java.lang.String"><![CDATA["Last " + $V{prop}.getProperty("abcd")]]></textFieldExpression> 
           </textField> 
          </band> 
         </pageHeader> 
         <columnHeader> 
          <band height="20" isSplitAllowed="true" > 
           <staticText> 
            <reportElement 
             x="0" 
             y="0" 
             width="96" 
             height="20" 
             key="staticText-2"/> 
            <box></box> 
            <textElement> 
             <font/> 
            </textElement> 
           <text><![CDATA[CustomerName]]></text> 
           </staticText> 
           <staticText> 
            <reportElement 
             x="96" 
             y="0" 
             width="100" 
             height="20" 
             key="staticText-3"/> 
            <box></box> 
            <textElement> 
             <font/> 
            </textElement> 
           <text><![CDATA[Workorderid]]></text> 
           </staticText> 
          </band> 
         </columnHeader> 
         <detail> 
          <band height="18" isSplitAllowed="true" > 
           <textField isStretchWithOverflow="true" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > 
            <reportElement 
             x="0" 
             y="0" 
             width="96" 
             height="18" 
             key="textField"/> 
            <box></box> 
            <textElement> 
             <font/> 
            </textElement> 
           <textFieldExpression class="java.lang.String"><![CDATA[$F{NAME}+"This\nwill\ncause\na\nsplit."]]></textFieldExpression> 
           </textField> 
           <textField isStretchWithOverflow="false" pattern="##0.00" isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > 
            <reportElement 
             x="96" 
             y="0" 
             width="100" 
             height="18" 
             key="textField"/> 
            <box></box> 
            <textElement> 
             <font/> 
            </textElement> 
           <textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{ID}]]></textFieldExpression> 
           </textField> 
           <textField isStretchWithOverflow="false" isBlankWhenNull="false" evaluationTime="Band" hyperlinkType="None" hyperlinkTarget="Self" > 
            <reportElement 
             x="196" 
             y="0" 
             width="339" 
             height="0" 
             key="textField-5" 
             isRemoveLineWhenBlank="true"/> 
            <box></box> 
            <textElement> 
             <font/> 
            </textElement> 
           <textFieldExpression class="java.lang.String"><![CDATA[$V{prop}.setProperty("abcd", String.valueOf($F{ID}))]]></textFieldExpression> 
           </textField> 
          </band> 
         </detail> 
         <columnFooter> 
          <band height="0" isSplitAllowed="true" > 
          </band> 
         </columnFooter> 
         <pageFooter> 
          <band height="0" isSplitAllowed="true" > 
          </band> 
         </pageFooter> 
         <summary> 
          <band height="0" isSplitAllowed="true" > 
          </band> 
         </summary> 
    </jasperReport> 
    
関連する問題