【发布时间】:2014-01-29 15:48:02
【问题描述】:
我正在使用 Jasper 报告 基本上,我的问题是当字段为空时,我无法使用 Styles 标记中的条件样式更改背景颜色
我不知道条件语句的问题或条件为真时条件样式不能改变。
所以,我希望找到解决这个问题的方法,下面是我的报告文件代码:
<?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="FEP_ENERGY_DATA"
language="groovy" pageWidth="1333" pageHeight="1350" whenNoDataType="NoDataSection"
columnWidth="1293" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<property name="net.sf.jasperreports.style.evaluation.time.enabled" value="true"/>
<style name="style_TOU">
<conditionalStyle>
<conditionExpression><![CDATA[$F{TOTAL_EXP} == null]]></conditionExpression>
<style mode="Opaque" backcolor="#FFFF00"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$F{TOU1_KWH_EXP} == null]]></conditionExpression>
<style mode="Opaque" backcolor="#FFFF00"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$F{TOU2_KWH_EXP} == null]]></conditionExpression>
<style mode="Opaque" backcolor="#FFCC00"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$F{TOU3_KWH_EXP} == null]]></conditionExpression>
<style mode="Opaque" backcolor="#FF3300"/>
</conditionalStyle>
<conditionalStyle>
<conditionExpression><![CDATA[$F{TOU4_KWH_EXP} == null]]></conditionExpression>
<style mode="Opaque" backcolor="#77BCD4"/>
</conditionalStyle>
</style>
<parameter name="daydate" class="java.lang.String"/>
<parameter name="metersId" class="java.util.Collection"/>
<parameter name="imagepath" class="java.lang.String"/>
<queryString>
<![CDATA[WITH METER_ENERGY_DATA AS
(
SELECT MTR_INFO.MTR_ID, MTR_INFO.MTR_SLNO AS METER_SLNO ,MTR_INFO.ACCOUNT_NO AS ACCOUNT_NO, MTR_INFO.SUB_NO AS SUB_NO,
CONVERT(varchar,ENERGY_TOU.TOTAL_EXP) as TOTAL_EXP, CONVERT(varchar,ENERGY_TOU.TOU1_EXP) as TOU1_KWH_EXP,
CONVERT(varchar,ENERGY_TOU.TOU2_EXP) as TOU2_KWH_EXP, CONVERT(varchar,ENERGY_TOU.TOU3_EXP) as TOU3_KWH_EXP,
CONVERT(varchar,ENERGY_TOU.TOU4_EXP) as TOU4_KWH_EXP , ROW_NUMBER() OVER (PARTITION BY
ENERGY_TOU.METER_ID ORDER BY ENERGY_TOU.METER_TIME DESC) ROW_NUM
FROM AECMDMS_DEV.dbo.METER_INFO AS MTR_INFO
LEFT JOIN
(SELECT * FROM AECMDMS_DEV.dbo.ENERGY_WITH_TOU as ENERGY
WHERE ENERGY.METER_TIME BETWEEN '2014-01-10' AND '2014-01-10 23:59:59.999' ) AS ENERGY_TOU ON (ENERGY_TOU.METER_ID = MTR_INFO.MTR_ID)
)
SELECT METER_SLNO ,ACCOUNT_NO, SUB_NO, LEFT(TOTAL_EXP,LEN(TOTAL_EXP)-2) as TOTAL_EXP, LEFT(TOU1_KWH_EXP, LEN(TOU1_KWH_EXP)-2) AS TOU1_KWH_EXP ,LEFT(TOU2_KWH_EXP, LEN(TOU2_KWH_EXP)-2) AS TOU2_KWH_EXP, LEFT(TOU3_KWH_EXP, LEN(TOU3_KWH_EXP)-2) AS TOU3_KWH_EXP, LEFT(TOU4_KWH_EXP, LEN(TOU4_KWH_EXP)-2) AS TOU4_KWH_EXP
FROM METER_ENERGY_DATA AS MTR_ENERGY
WHERE MTR_ENERGY.ROW_NUM = 1
]]>
</queryString>
<field name="METER_SLNO" class="java.lang.String"/>
<field name="ACCOUNT_NO" class="java.lang.String"/>
<field name="SUB_NO" class="java.lang.String"/>
<field name="TOTAL_EXP" class="java.lang.String"/>
<field name="TOU1_KWH_EXP" class="java.lang.String"/>
<field name="TOU2_KWH_EXP" class="java.lang.String"/>
<field name="TOU3_KWH_EXP" class="java.lang.String"/>
<field name="TOU4_KWH_EXP" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="102" splitType="Stretch">
<image scaleImage="FillFrame">
<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="421" y="0" width="370" height="70"/>
<imageExpression><![CDATA[$P{imagepath}]]></imageExpression>
</image>
<textField>
<reportElement x="2" y="81" width="1292" height="20"/>
<textElement textAlignment="Center">
<font size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["ENERGY DATA EXPORT ON "+$P{daydate}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="31" splitType="Stretch">
<frame>
<reportElement x="0" y="20" width="1292" height="10"/>
</frame>
</band>
</pageHeader>
<columnHeader>
<band height="40" splitType="Stretch">
<frame>
<reportElement x="2" y="0" width="1294" height="40"/>
<staticText>
<reportElement mode="Opaque" x="564" y="20" width="110" height="20" forecolor="#000000" backcolor="#77BCD4"/>
<box rightPadding="5">
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[TOTAL]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" style="style_TOU" x="674" y="20" width="110" height="20" forecolor="#000000" backcolor="#77BCD4"/>
<box rightPadding="5">
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[TOU 1]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="784" y="20" width="110" height="20" forecolor="#000000" backcolor="#77BCD4"/>
<box rightPadding="5">
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[TOU 2]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="894" y="20" width="110" height="20" forecolor="#000000" backcolor="#77BCD4"/>
<box rightPadding="5">
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[TOU 3]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="1004" y="20" width="110" height="20" forecolor="#000000" backcolor="#77BCD4"/>
<box rightPadding="5">
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[TOU 4]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="564" y="0" width="550" height="20" forecolor="#000000" backcolor="#77BCD4"/>
<box>
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
<bottomPen lineWidth="0.5" lineColor="#CCCCCC"/>
<rightPen lineWidth="0.5" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[Active Energy(kWh)]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="178" y="0" width="130" height="40" forecolor="#000000" backcolor="#77BCD4"/>
<box leftPadding="5">
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[Serial No.]]></text>
</staticText>
<staticText>
<reportElement mode="Opaque" x="436" y="0" width="128" height="40" forecolor="#000000" backcolor="#77BCD4"/>
<box rightPadding="5">
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[Subscribtion No.]]></text>
</staticText>
</frame>
<staticText>
<reportElement mode="Opaque" x="310" y="0" width="128" height="40" forecolor="#000000" backcolor="#77BCD4"/>
<box rightPadding="5">
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font fontName="Arial" size="10" isBold="true"/>
</textElement>
<text><![CDATA[Account No.]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="24" splitType="Stretch">
<rectangle>
<reportElement x="180" y="0" width="936" height="24" isRemoveLineWhenBlank="true" backcolor="#D0E8F0">
<printWhenExpression><![CDATA[$V{REPORT_COUNT}.intValue() % 2 != 1]]></printWhenExpression>
</reportElement>
<graphicElement>
<pen lineWidth="0.0" lineColor="#CCCCCC"/>
</graphicElement>
</rectangle>
<frame>
<reportElement x="180" y="0" width="936" height="24" backcolor="#FFFFFF"/>
<textField pattern="###0.0">
<reportElement mode="Transparent" x="258" y="0" width="128" height="24" backcolor="#CCCCCC"/>
<box rightPadding="3">
<pen lineWidth="0.75" lineColor="#CCCCCC"/>
<topPen lineWidth="0.75" lineColor="#CCCCCC"/>
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
<bottomPen lineWidth="0.75" lineColor="#CCCCCC"/>
<rightPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{SUB_NO}+" "]]></textFieldExpression>
</textField>
<textField evaluationTime="Band">
<reportElement mode="Transparent" style="style_TOU" x="386" y="0" width="110" height="24"/>
<box rightPadding="3">
<pen lineWidth="0.75" lineColor="#CCCCCC"/>
<topPen lineWidth="0.75" lineColor="#CCCCCC"/>
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
<bottomPen lineWidth="0.75" lineColor="#CCCCCC"/>
<rightPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{TOTAL_EXP} == null ? "n/a" : $F{TOTAL_EXP} +" "]]></textFieldExpression>
</textField>
<textField evaluationTime="Band">
<reportElement mode="Transparent" style="style_TOU" x="496" y="0" width="110" height="24"/>
<box rightPadding="3">
<pen lineWidth="0.75" lineColor="#CCCCCC"/>
<topPen lineWidth="0.75" lineColor="#CCCCCC"/>
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
<bottomPen lineWidth="0.75" lineColor="#CCCCCC"/>
<rightPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{TOU1_KWH_EXP}== null ? "n/a" : $F{TOU1_KWH_EXP} +" "]]></textFieldExpression>
</textField>
<textField evaluationTime="Band">
<reportElement mode="Transparent" style="style_TOU" x="606" y="0" width="110" height="24"/>
<box rightPadding="3">
<pen lineWidth="0.75" lineColor="#CCCCCC"/>
<topPen lineWidth="0.75" lineColor="#CCCCCC"/>
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
<bottomPen lineWidth="0.75" lineColor="#CCCCCC"/>
<rightPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{TOU2_KWH_EXP} == null ? "n/a" : $F{TOU2_KWH_EXP}+" "]]></textFieldExpression>
</textField>
<textField evaluationTime="Band">
<reportElement mode="Transparent" style="style_TOU" x="716" y="0" width="110" height="24"/>
<box rightPadding="3">
<pen lineWidth="0.75" lineColor="#CCCCCC"/>
<topPen lineWidth="0.75" lineColor="#CCCCCC"/>
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
<bottomPen lineWidth="0.75" lineColor="#CCCCCC"/>
<rightPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{TOU3_KWH_EXP} == null ? "n/a" : $F{TOU3_KWH_EXP} +" "]]></textFieldExpression>
</textField>
<textField evaluationTime="Band">
<reportElement mode="Transparent" style="style_TOU" x="826" y="0" width="110" height="24"/>
<box rightPadding="3">
<pen lineWidth="0.75" lineColor="#CCCCCC"/>
<topPen lineWidth="0.75" lineColor="#CCCCCC"/>
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
<bottomPen lineWidth="0.75" lineColor="#CCCCCC"/>
<rightPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{TOU4_KWH_EXP} == null ? "n/a" : $F{TOU4_KWH_EXP} +" "]]></textFieldExpression>
</textField>
<textField pattern="###0.0">
<reportElement mode="Transparent" x="130" y="0" width="126" height="24" backcolor="#CCCCCC"/>
<box rightPadding="3">
<pen lineWidth="0.75" lineColor="#CCCCCC"/>
<topPen lineWidth="0.75" lineColor="#CCCCCC"/>
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
<bottomPen lineWidth="0.75" lineColor="#CCCCCC"/>
<rightPen lineWidth="0.75" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{ACCOUNT_NO}+" "]]></textFieldExpression>
</textField>
<textField>
<reportElement mode="Transparent" x="0" y="0" width="130" height="24" backcolor="#CCCCCC"/>
<box leftPadding="5">
<topPen lineWidth="0.5" lineColor="#CCCCCC"/>
<leftPen lineWidth="0.75" lineColor="#CCCCCC"/>
<bottomPen lineWidth="0.5" lineColor="#CCCCCC"/>
<rightPen lineWidth="0.5" lineColor="#CCCCCC"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$F{METER_SLNO}]]></textFieldExpression>
</textField>
</frame>
</band>
</detail>
<pageFooter>
<band height="20" splitType="Stretch">
<textField>
<reportElement x="994" y="0" width="80" height="20"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="1074" y="0" width="42" height="20"/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}+" "]]></textFieldExpression>
</textField>
<textField pattern="dd/MM/yyyy h.mm a">
<reportElement x="182" y="0" width="100" height="20"/>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</band>
</pageFooter>
<noData>
<band height="33" splitType="Stretch">
<staticText>
<reportElement x="522" y="0" width="291" height="31"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="24" isBold="true"/>
</textElement>
<text><![CDATA[No Data To Display]]></text>
</staticText>
</band>
</noData>
【问题讨论】:
标签: java jasper-reports report