2012-03-22 74 views
7

我是iReport。所以我想根據數據做一個簡單的報告。iReport:獲取表格的多個副本

我的問題是,當我的行少於細節帶的大小,整個表得到重複的詳細帶,我不想再次。如果我的行大約是5,那麼相同的表被複制4次詳細的樂隊,而不僅僅是桌子,而是我詳細列出的每一件事情。它會一直重複,直到細節帶限制來臨。

所以我犯了一些錯誤,或者我必須在iReport中設置一些細節帶的屬性?

請幫我朋友。提前致謝。

這是生成的結果:

Generated result

這裏是我的JRXML代碼:

<?xml version="1.0" encoding="UTF-8"?> 
<jasperReport language="groovy" bottomMargin="20" topMargin="20" rightMargin="20" leftMargin="20" columnWidth="555" 
       whenNoDataType="AllSectionsNoDetail" pageHeight="842" pageWidth="595" name="test" 
       xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       xmlns="http://jasperreports.sourceforge.net/jasperreports"> 
    <property name="ireport.zoom" value="1.0"/> 
    <property name="ireport.x" value="0"/> 
    <property name="ireport.y" value="0"/> 
    <style name="table"> 
     <box> 
      <pen lineColor="#000000" lineWidth="1.0"/> 
     </box> 
    </style> 
    <style name="table_TH" backcolor="#F0F8FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table_CH" backcolor="#BFE1FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table_TD" backcolor="#FFFFFF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 1"> 
     <box> 
      <pen lineColor="#000000" lineWidth="1.0"/> 
     </box> 
    </style> 
    <style name="table 1_TH" backcolor="#F0F8FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 1_CH" backcolor="#BFE1FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 1_TD" backcolor="#FFFFFF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 2"> 
     <box> 
      <pen lineColor="#000000" lineWidth="1.0"/> 
     </box> 
    </style> 
    <style name="table 2_TH" backcolor="#F0F8FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 2_CH" backcolor="#BFE1FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 2_TD" backcolor="#FFFFFF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 3"> 
     <box> 
      <pen lineColor="#000000" lineWidth="1.0"/> 
     </box> 
    </style> 
    <style name="table 3_TH" backcolor="#F0F8FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 3_CH" backcolor="#BFE1FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 3_TD" backcolor="#FFFFFF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 4"> 
     <box> 
      <pen lineColor="#000000" lineWidth="1.0"/> 
     </box> 
    </style> 
    <style name="table 4_TH" backcolor="#F0F8FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 4_CH" backcolor="#BFE1FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 4_TD" backcolor="#FFFFFF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 5"> 
     <box> 
      <pen lineColor="#000000" lineWidth="1.0"/> 
     </box> 
    </style> 
    <style name="table 5_TH" backcolor="#F0F8FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 5_CH" backcolor="#BFE1FF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <style name="table 5_TD" backcolor="#FFFFFF" mode="Opaque"> 
     <box> 
      <pen lineColor="#000000" lineWidth="0.5"/> 
     </box> 
    </style> 
    <subDataset name="a"> 
     <parameter name="sem" class="java.lang.String"> 
      <defaultValueExpression> 
       <![CDATA[]]> 
      </defaultValueExpression> 
     </parameter> 
     <queryString> 
      <![CDATA[select final."M" as "ENROLLMENT",sem_batch.sem,sem_batch.batch,final."N" as "TTL_WKDY",final."O" as "PRESENT",round(((100*"O")/"N"),2) as "PERCENTAGE" from sem_batch, (select m."Std_id" as "M",l."Batch" as "L",l."Btch" as "N",m."Std" as "O" from (select count(b.batch_id) as "Btch",b.batch_id as "Batch" from batch_wkday b where b.batch_id like $P{sem} group by batch_id) l, (select count(a.std_id) as "Std",a.std_id as "Std_id",s.batch_id as "Batch" from attendance a,student_detail s where a.std_id=s.std_id and s.batch_id like $P{sem} group by a.std_id,s.batch_id) m where l."Batch"=m."Batch") final where final."L"=sem_batch.batch_id]]> 
     </queryString> 
     <field name="ENROLLMENT" class="java.math.BigDecimal"/> 
     <field name="SEM" class="java.math.BigDecimal"/> 
     <field name="BATCH" class="java.lang.String"/> 
     <field name="TTL_WKDY" class="java.math.BigDecimal"/> 
     <field name="PRESENT" class="java.math.BigDecimal"/> 
     <field name="PERCENTAGE" class="java.math.BigDecimal"/> 
     <group name="ENROLLMENT"> 
      <groupExpression> 
       <![CDATA[$F{ENROLLMENT}]]> 
      </groupExpression> 
     </group> 
    </subDataset> 
    <parameter name="SEM" class="java.lang.String"/> 
    <queryString> 
     <![CDATA[select * from sem_batch]]> 
    </queryString> 
    <field name="SEM" class="java.math.BigDecimal"/> 
    <field name="BATCH" class="java.lang.String"/> 
    <field name="BATCH_ID" class="java.lang.String"/> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <title> 
     <band splitType="Stretch" height="69"> 
      <staticText> 
       <reportElement height="53" width="421" y="0" x="68"/> 
       <textElement markup="none" textAlignment="Center"> 
        <font size="22"/> 
       </textElement> 
       <text> 
        <![CDATA[ATTENDANCE - CLASS ]]> 
       </text> 
      </staticText> 
     </band> 
    </title> 
    <pageHeader> 
     <band splitType="Stretch"/> 
    </pageHeader> 
    <columnHeader> 
     <band splitType="Stretch" height="61"> 
      <staticText> 
       <reportElement height="20" width="53" y="0" x="0"/> 
       <textElement> 
        <font size="12"/> 
       </textElement> 
       <text> 
        <![CDATA[SEM]]> 
       </text> 
      </staticText> 
      <staticText> 
       <reportElement height="20" width="53" y="20" x="0"/> 
       <textElement> 
        <font size="12"/> 
       </textElement> 
       <text> 
        <![CDATA[DATE]]> 
       </text> 
      </staticText> 
      <staticText> 
       <reportElement height="20" width="10" y="0" x="58"/> 
       <textElement/> 
       <text> 
        <![CDATA[:]]> 
       </text> 
      </staticText> 
      <staticText> 
       <reportElement height="20" width="10" y="20" x="58"/> 
       <textElement/> 
       <text> 
        <![CDATA[:]]> 
       </text> 
      </staticText> 
      <textField pattern="dd/MM/yyyy"> 
       <reportElement height="20" width="100" y="20" x="68"/> 
       <textElement/> 
       <textFieldExpression> 
        <![CDATA[new java.util.Date()]]> 
       </textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement height="20" width="100" y="0" x="68"/> 
       <textElement/> 
       <textFieldExpression> 
        <![CDATA[$P{SEM}]]> 
       </textFieldExpression> 
      </textField> 
     </band> 
    </columnHeader> 
    <detail> 
     <band splitType="Stretch" height="125"> 
      <componentElement> 
       <reportElement height="50" width="360" y="0" x="35" style="table 5" key="table 5"/> 
       <jr:table 
         xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" 
         xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components"> 
        <datasetRun subDataset="a"> 
         <datasetParameter name="sem"> 
          <datasetParameterExpression> 
           <![CDATA[$P{SEM}+'%']]> 
          </datasetParameterExpression> 
         </datasetParameter> 
         <connectionExpression> 
          <![CDATA[$P{REPORT_CONNECTION}]]> 
         </connectionExpression> 
        </datasetRun> 
        <jr:column width="118"> 
         <jr:columnHeader height="23" style="table 5_CH" rowSpan="1"> 
          <staticText> 
           <reportElement height="20" width="118" y="0" x="0"/> 
           <textElement textAlignment="Center"> 
            <font size="14" isBold="false"/> 
           </textElement> 
           <text> 
            <![CDATA[ENROLLMENT]]> 
           </text> 
          </staticText> 
         </jr:columnHeader> 
         <jr:detailCell height="20" style="table 5_TD" rowSpan="1"> 
          <textField> 
           <reportElement height="20" width="118" y="0" x="0"/> 
           <textElement textAlignment="Center"> 
            <font size="10" isBold="false"/> 
           </textElement> 
           <textFieldExpression> 
            <![CDATA[$F{ENROLLMENT}]]> 
           </textFieldExpression> 
          </textField> 
         </jr:detailCell> 
        </jr:column> 
        <jr:column width="90"> 
         <jr:columnHeader height="23" style="table 5_CH" rowSpan="1"> 
          <staticText> 
           <reportElement height="20" width="90" y="0" x="0"/> 
           <textElement textAlignment="Center"> 
            <font size="14"/> 
           </textElement> 
           <text> 
            <![CDATA[SEM]]> 
           </text> 
          </staticText> 
         </jr:columnHeader> 
         <jr:detailCell height="20" style="table 5_TD" rowSpan="1"> 
          <textField> 
           <reportElement height="20" width="90" y="0" x="0"/> 
           <textElement textAlignment="Center"> 
            <font size="10"/> 
           </textElement> 
           <textFieldExpression> 
            <![CDATA[$F{SEM}]]> 
           </textFieldExpression> 
          </textField> 
         </jr:detailCell> 
        </jr:column> 
        <jr:column width="90"> 
         <jr:columnHeader height="23" style="table 5_CH" rowSpan="1"> 
          <staticText> 
           <reportElement height="20" width="90" y="0" x="0"/> 
           <textElement textAlignment="Center"> 
            <font size="14"/> 
           </textElement> 
           <text> 
            <![CDATA[BATCH]]> 
           </text> 
          </staticText> 
         </jr:columnHeader> 
         <jr:detailCell height="20" style="table 5_TD" rowSpan="1"> 
          <textField> 
           <reportElement height="20" width="90" y="0" x="0"/> 
           <textElement textAlignment="Center"/> 
           <textFieldExpression> 
            <![CDATA[$F{BATCH}]]> 
           </textFieldExpression> 
          </textField> 
         </jr:detailCell> 
        </jr:column> 
        <jr:column width="90"> 
         <jr:columnHeader height="23" style="table 5_CH" rowSpan="1"> 
          <staticText> 
           <reportElement height="20" width="90" y="0" x="0"/> 
           <textElement textAlignment="Center"> 
            <font size="14"/> 
           </textElement> 
           <text> 
            <![CDATA[PRESENT]]> 
           </text> 
          </staticText> 
         </jr:columnHeader> 
         <jr:detailCell height="20" style="table 5_TD" rowSpan="1"> 
          <textField> 
           <reportElement height="20" width="90" y="0" x="0"/> 
           <textElement textAlignment="Center"/> 
           <textFieldExpression> 
            <![CDATA[$F{PRESENT}]]> 
           </textFieldExpression> 
          </textField> 
         </jr:detailCell> 
        </jr:column> 
        <jr:column width="90"> 
         <jr:columnHeader height="23" style="table 5_CH" rowSpan="1"> 
          <staticText> 
           <reportElement height="20" width="90" y="0" x="0"/> 
           <textElement textAlignment="Center"> 
            <font size="14"/> 
           </textElement> 
           <text> 
            <![CDATA[PERCENTAGE]]> 
           </text> 
          </staticText> 
         </jr:columnHeader> 
         <jr:detailCell height="20" style="table 5_TD" rowSpan="1"> 
          <textField> 
           <reportElement height="20" width="90" y="0" x="0"/> 
           <textElement textAlignment="Center"/> 
           <textFieldExpression> 
            <![CDATA[$F{PERCENTAGE}]]> 
           </textFieldExpression> 
          </textField> 
         </jr:detailCell> 
        </jr:column> 
       </jr:table> 
      </componentElement> 
     </band> 
    </detail> 
    <columnFooter> 
     <band splitType="Stretch"/> 
    </columnFooter> 
    <pageFooter> 
     <band splitType="Stretch" height="54"> 
      <textField> 
       <reportElement height="20" width="100" y="16" x="227"/> 
       <textElement textAlignment="Center"/> 
       <textFieldExpression> 
        <![CDATA[$V{PAGE_NUMBER}]]> 
       </textFieldExpression> 
      </textField> 
     </band> 
    </pageFooter> 
    <summary> 
     <band splitType="Stretch" height="42"/> 
    </summary> 
</jasperReport> 
+0

嗨,歡迎來到SO。你能更詳細地解釋你的設計報告格式嗎?有一些解釋的圖片或JRXML文件會很有幫助。 – 2012-03-22 03:07:31

+0

是啊當然...在這裏我附加文件,以便您可以看到jrxml文件以及PDF文件也... – 2012-03-22 03:28:45

+1

我無法讀取您的jrxml文件,它不適用於priview。你可以用代碼塊直接粘貼到你的文章中。 – 2012-03-22 03:59:25

回答

9

你應該把table組件到Title帶(或成Summary band,for例子)。不進Detail帶。

+0

嘿,最後我得到了完整的解決方案.. – 2012-04-01 07:11:53

+0

當我這樣做時,我的報告預覽中只有很大的空間。我能做些什麼來防止這種情況發生? – 2014-04-14 06:48:35

0

嘿,我得到了我的問題的解決方案。如果在主查詢中返回多行,則會發生這種情況。嘗試給出返回不超過一行的查詢。像「從雙選擇1」。該解決方案解決了我的問題

+0

在哪裏寫這個「從雙選擇1」? – 2012-12-18 09:28:48

+0

在主報告查詢中寫入此查詢。右鍵單擊報告後可以找到該查詢編輯器,然後轉到編輯查詢選項。 – 2013-01-09 07:23:15

8

選擇表格屬性,並在表中添加 printWhenExpression$ V {} REPORT_COUNT == 1我們避免在iREPORT分享到人人repetation表值。

3

根據以前的答案回答,我可以使用Detail部分的表格和以下屬性設置,以避免在文檔結尾處生成重複的或空白的頁面。

詳細樂隊 - >設置打印時表達與價值$ V {} REPORT_COUNT == 1 表元素 - >設置打印當表達 $ V {} REPORT_COUNT == 1