2012-06-28 31 views
2

我怎樣才能在具有多個字段的iReport中編寫組表達式?報告輸出應如下所示。iReport組表達式多個字段

Buyer Product Unit Quantity Total 
------------------------------------------ 
Buyer2 Banana Count 50 
            50 
Buyer2 Banana Kg  5 
Buyer2 Banana Kg  5 
            10 
Buyer2 Coconut Count 20 
            20 
Buyer4 Papaya Count 500 
            500 
Buyer4 Mango Count 200 
            200 
Buyer5 Banana Kg  15 
Buyer5 Banana Kg  15 
            30 
+2

你爲什麼要離開這個問題打開?你不滿意?下面給我的答案似乎很正確的嗎? –

回答

0

這個最簡單的事情就是創建多個組。所以在你的例子中,你會使用三個組,一個用於買方,產品和單位。然後,您可以使用一個變量對數量進行求和並使其與單位組重新設置。

下面是一個基本的例子JRXML,你可以適應:

<?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="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b478862e-b118-4290-8664-eae9b2966b31"> 
    <parameter name="GROUP_BY" class="java.lang.String"> 
     <defaultValueExpression><![CDATA[$F{field1}]]></defaultValueExpression> 
    </parameter> 
    <field name="buyer" class="java.lang.String"/> 
    <field name="product" class="java.lang.String"/> 
    <field name="unit" class="java.lang.Number"/> 
    <field name="quantity" class="java.lang.String"/> 
    <variable name="sumQuantity" class="java.lang.Number" resetType="Group" resetGroup="unit" calculation="Sum"/> 
    <group name="Buyer"> 
     <groupExpression><![CDATA[$F{buyer}]]></groupExpression> 
    </group> 
    <group name="product"> 
     <groupExpression><![CDATA[$F{product}]]></groupExpression> 
    </group> 
    <group name="unit"> 
     <groupExpression><![CDATA[$F{unit}]]></groupExpression> 
     <groupFooter> 
      <band height="26"> 
       <textField> 
        <reportElement uuid="d1f95335-0fee-4d75-ac0d-74f0dc478a78" x="400" y="0" width="100" height="20"/> 
        <textElement/> 
        <textFieldExpression><![CDATA[$V{sumQuantity}]]></textFieldExpression> 
       </textField> 
      </band> 
     </groupFooter> 
    </group> 
    <columnHeader> 
     <band height="21" splitType="Stretch"> 
      <staticText> 
       <reportElement uuid="c4ee8763-fb32-4805-9bcd-4b407bd7ae35" x="0" y="0" width="100" height="20"/> 
       <textElement/> 
       <text><![CDATA[buyer]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="5c5e099b-f2b4-4c98-b428-bc3983711136" x="100" y="0" width="100" height="20"/> 
       <textElement/> 
       <text><![CDATA[product]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="1bff9ddd-fa17-4b7f-bc00-032653cf2307" x="200" y="0" width="100" height="20"/> 
       <textElement/> 
       <text><![CDATA[unit]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="94e75612-cee4-45e9-97c0-a0d1b8ac6269" x="300" y="0" width="100" height="20"/> 
       <textElement/> 
       <text><![CDATA[quantity]]></text> 
      </staticText> 
      <staticText> 
       <reportElement uuid="92e83a6d-198f-4ee1-95eb-295cb2415136" x="400" y="0" width="100" height="20"/> 
       <textElement/> 
       <text><![CDATA[total]]></text> 
      </staticText> 
     </band> 
    </columnHeader> 
    <detail> 
     <band height="23" splitType="Stretch"> 
      <textField> 
       <reportElement uuid="927b66fa-f4aa-4acf-ac85-fde9164bc974" x="0" y="0" width="100" height="20"/> 
       <textElement/> 
       <textFieldExpression><![CDATA[$F{buyer}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement uuid="f5e8d24f-5529-489d-94b9-78b86b09adda" x="100" y="0" width="100" height="20"/> 
       <textElement/> 
       <textFieldExpression><![CDATA[$F{product}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement uuid="9c9f129b-64c7-40d5-a0a9-af2069d58296" x="200" y="0" width="100" height="20"/> 
       <textElement/> 
       <textFieldExpression><![CDATA[$F{unit}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement uuid="d9443c16-dcac-4a72-b85f-d961c215aee4" x="300" y="0" width="100" height="20"/> 
       <textElement/> 
       <textFieldExpression><![CDATA[$F{quantity}]]></textFieldExpression> 
      </textField> 
     </band> 
    </detail> 
</jasperReport>