我有一个类别和客户表,如下图所示:
然后我想从这些表中进行报告,并在jasper中按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>
此文件的结果如下:
但我希望我有这样的结果:
我该怎么做?
答案 0 :(得分: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的“使用样式”部分
中进行了描述