2014-11-14 62 views
1

我有你在我的數據庫下面看的類別和客戶表:如何更改組更改時的細節帶顏色?

enter image description here

然後我想打從這些表報告和碧玉由category id分組。這是我的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="jasper" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"> 
    <queryString language="plsql"> 
     <![CDATA[select c.cid as "CID", c.title, j.id, j.name, j.family 
    from Jasper j 
    join Category c 
    on j.c_id = c.cid]]> 
    </queryString> 
    <field name="CID" class="java.lang.String"> 
     <fieldDescription><![CDATA[]]></fieldDescription> 
    </field> 
    <field name="TITLE" class="java.lang.String"> 
     <fieldDescription><![CDATA[]]></fieldDescription> 
    </field> 
    <field name="ID" class="java.lang.String"> 
     <fieldDescription><![CDATA[]]></fieldDescription> 
    </field> 
    <field name="NAME" class="java.lang.String"> 
     <fieldDescription><![CDATA[]]></fieldDescription> 
    </field> 
    <field name="FAMILY" class="java.lang.String"> 
     <fieldDescription><![CDATA[]]></fieldDescription> 
    </field> 
    <group name="category"> 
     <groupExpression><![CDATA[$F{CID}]]></groupExpression> 
     <groupFooter> 
      <band> 
       <frame> 
        <reportElement x="1" y="0" width="212" height="0"/> 
        <box> 
         <topPen lineWidth="0.5"/> 
        </box> 
       </frame> 
      </band> 
     </groupFooter> 
    </group> 
    <background> 
     <band splitType="Stretch"/> 
    </background> 
    <pageHeader> 
     <band height="33" splitType="Stretch"> 
      <staticText> 
       <reportElement x="196" y="1" width="162" height="32"/> 
       <textElement textAlignment="Center" verticalAlignment="Middle"> 
        <font fontName="Consolas" size="20" isBold="true" isItalic="true"/> 
       </textElement> 
       <text><![CDATA[Jasper]]></text> 
      </staticText> 
     </band> 
    </pageHeader> 
    <columnHeader> 
     <band height="20" splitType="Stretch"> 
      <staticText> 
       <reportElement mode="Opaque" x="213" y="0" width="100" height="20" backcolor="#F0F0F0"/> 
       <box> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle"> 
        <font fontName="Consolas"/> 
       </textElement> 
       <text><![CDATA[ID]]></text> 
      </staticText> 
      <staticText> 
       <reportElement mode="Opaque" x="313" y="0" width="100" height="20" backcolor="#F0F0F0"/> 
       <box> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle"> 
        <font fontName="Consolas"/> 
       </textElement> 
       <text><![CDATA[Name]]></text> 
      </staticText> 
      <staticText> 
       <reportElement mode="Opaque" x="413" y="0" width="100" height="20" backcolor="#F0F0F0"/> 
       <box> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle"> 
        <font fontName="Consolas"/> 
       </textElement> 
       <text><![CDATA[Family]]></text> 
      </staticText> 
      <staticText> 
       <reportElement mode="Opaque" x="1" y="0" width="100" height="20" backcolor="#F0F0F0"/> 
       <box> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle"> 
        <font fontName="Consolas"/> 
       </textElement> 
       <text><![CDATA[CID]]></text> 
      </staticText> 
      <staticText> 
       <reportElement mode="Opaque" x="101" y="0" width="112" height="20" backcolor="#F0F0F0"/> 
       <box> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement textAlignment="Center" verticalAlignment="Middle"> 
        <font fontName="Consolas"/> 
       </textElement> 
       <text><![CDATA[Title]]></text> 
      </staticText> 
     </band> 
    </columnHeader> 
    <detail> 
     <band height="20" splitType="Stretch"> 
      <textField> 
       <reportElement x="213" y="0" width="100" height="20"/> 
       <box leftPadding="5"> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement> 
        <font fontName="Consolas"/> 
       </textElement> 
       <textFieldExpression class="java.lang.String"><![CDATA[$F{ID}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="313" y="0" width="100" height="20"/> 
       <box leftPadding="5"> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement> 
        <font fontName="Consolas"/> 
       </textElement> 
       <textFieldExpression class="java.lang.String"><![CDATA[$F{NAME}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="413" y="0" width="100" height="20"/> 
       <box leftPadding="5"> 
        <topPen lineWidth="0.5"/> 
        <leftPen lineWidth="0.5"/> 
        <bottomPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
       <textElement> 
        <font fontName="Consolas"/> 
       </textElement> 
       <textFieldExpression class="java.lang.String"><![CDATA[$F{FAMILY}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="1" y="0" width="100" height="20"> 
        <printWhenExpression><![CDATA[new Boolean($V{category_COUNT}.longValue() == 1 ? true : false)]]></printWhenExpression> 
       </reportElement> 
       <box leftPadding="5"> 
        <topPen lineWidth="0.0"/> 
        <leftPen lineWidth="0.0"/> 
        <bottomPen lineWidth="0.0"/> 
        <rightPen lineWidth="0.0"/> 
       </box> 
       <textElement verticalAlignment="Middle"> 
        <font fontName="Consolas"/> 
       </textElement> 
       <textFieldExpression class="java.lang.String"><![CDATA[$F{CID}]]></textFieldExpression> 
      </textField> 
      <textField> 
       <reportElement x="101" y="0" width="112" height="20"> 
        <printWhenExpression><![CDATA[new Boolean($V{category_COUNT}.longValue() == 1 ? true : false)]]></printWhenExpression> 
       </reportElement> 
       <box leftPadding="5"> 
        <topPen lineWidth="0.0"/> 
        <leftPen lineWidth="0.0"/> 
        <bottomPen lineWidth="0.0"/> 
        <rightPen lineWidth="0.0"/> 
       </box> 
       <textElement verticalAlignment="Middle"> 
        <font fontName="Consolas"/> 
       </textElement> 
       <textFieldExpression class="java.lang.String"><![CDATA[$F{TITLE}]]></textFieldExpression> 
      </textField> 
      <frame> 
       <reportElement x="1" y="0" width="100" height="20"/> 
       <box> 
        <leftPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
      </frame> 
      <frame> 
       <reportElement x="101" y="0" width="112" height="20"/> 
       <box> 
        <leftPen lineWidth="0.5"/> 
        <rightPen lineWidth="0.5"/> 
       </box> 
      </frame> 
     </band> 
    </detail> 
</jasperReport> 

結果這個文件是這樣的:

enter image description here

但我想TI具有導致這樣的:

enter image description here

如何我可以那樣做嗎?

+0

出事了與圖像「與樣式工作」 ... – jjlema

+0

那你是什麼意思? –

+0

對不起,它是我的錯,我無法看到圖像。 – jjlema

回答

0

您可以使用條件式樣。 定義的風格是這樣的:

<style name="myStyle"> 
    <box> 
     <pen lineWidth="0.25"/> 
     <topPen lineWidth="0.25"/> 
     <leftPen lineWidth="0.25"/> 
     <bottomPen lineWidth="0.25"/> 
     <rightPen lineWidth="0.25"/> 
    </box> 
    <conditionalStyle> 
     <conditionExpression><![CDATA[($F{CID} % 2) != 0]]></conditionExpression> 
     <style mode="Opaque" forecolor="#000000" backcolor="#FFFF00"/> 
    </conditionalStyle> 
    <conditionalStyle> 
     <conditionExpression><![CDATA[($F{CID} % 2) == 0]]></conditionExpression> 
     <style forecolor="#000000" backcolor="#FFFFFF"/> 
    </conditionalStyle> 
</style> 

將詳細部分中的所有領域成爲幀,將這種風格的框架。

此描述iReportUltimateGuide在部分

+0

如果類別被刪除,那麼此解決方案不起作用。例如,如果類別ID是這樣的:** 1,2,4 ** –

+0

使用JR的變量。例如 <變量名稱=「GROUPORDERNUM」class =「java.lang.Integer」calculation =「DistinctCount」> \t \t <![CDATA [$ F {CID}]]> \t \t \t' – sanBez