1
如何根據參數構造標題標題?JasperReports:如何根據參數構造標題標題
例如,我有一個日期,周,月和年的報告。我有一個參數,但我不知道如何在標題中顯示它。
我要的是:
If I put parameter $P{date1} and $P{date2} then it will show 'Date range from $P{date1} and $P{date2}' for header 1
else if parameter $P{w}$P{month}$P{year} then 'For weekly $P{w}$P{month}$P{year}' for header 2
else if parameter $P{month}$P{year} then 'For monthly $P{month}$P{year}' for header 3
else if parameter $P{q}$P{year} then 'For quarter $P{q}$P{year}' for header 4
else if parameter $P{year} then 'For yearly $P{year}' for header 5
更新: - 我有新的問題,當我運行報告,我的輸出無法正確顯示。 這是我的代碼: -
<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="Company Profile by Date Registered" pageWidth="595" pageHeight="842" whenNoDataType="NoDataSection" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="daterangefrom" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="daterangeto" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="monthy" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="yrs" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="quarter" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="weeks" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[select a.entered,
a.modified,
a.org_id,
a.name,
a.organization_type,
c.description as companygroup,lead,
a.industry_temp_code,
b.description,
a.equity_structure,a.operation_date from organization a
left join lookup_industry_group b on a.industry_temp_code = b.code
left join lookup_company_group c on c.code = a.company_group
left join ticket d on d.org_id = a.org_id
where
((d.entered BETWEEN $P{daterangefrom} AND $P{daterangeto}) or ($P{daterangefrom} =' ' AND $P{daterangeto} =' '))
AND
((datename(month,d.entered) = $P{monthy}) or ($P{monthy} = ' '))
AND
((datename(year,d.entered) = $P{yrs}) or ($P{yrs} = ' '))
AND
((datepart(qq, d.entered) = $P{quarter}) or ($P{quarter} = ' '))
AND
((DATEPART(day, d.entered - 1)/7 + 1 = $P{weeks}) or ($P{weeks} = ' '))]]>
</queryString>
<field name="entered" class="java.sql.Timestamp"/>
<field name="modified" class="java.sql.Timestamp"/>
<field name="org_id" class="java.lang.Integer"/>
<field name="name" class="java.lang.String"/>
<field name="organization_type" class="java.lang.String"/>
<field name="companygroup" class="java.lang.String"/>
<field name="lead" class="java.lang.String"/>
<field name="industry_temp_code" class="java.lang.Integer"/>
<field name="description" class="java.lang.String"/>
<field name="equity_structure" class="java.lang.String"/>
<field name="operation_date" class="java.sql.Timestamp"/>
<title>
<band height="79" splitType="Stretch">
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement x="18" y="14" width="537" height="41" isRemoveLineWhenBlank="true"/>
<textElement/>
<textFieldExpression><![CDATA[(($P{daterangefrom} != null) && ($P{daterangeto} != null)) ? "Date range from " + $P{daterangefrom} + " and " + $P{daterangeto}
: (($P{weeks} != null) && ($P{monthy} != null) && ($P{yrs} != null)) ? "For weekly " +$P{weeks} + $P{monthy} + $P{yrs}
: (($P{monthy} != null) && ($P{yrs} != null)) ? "For monthly " + $P{monthy} + $P{yrs}
: (($P{quarter} != null) && ($P{yrs} != null)) ? "For quarter " + $P{quarter} + $P{yrs}
: (($P{yrs} != null)) ? "For yearly " + $P{yrs} : null]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
我有嘗試你的代碼,但你show.can檢查it.This的錯誤是我的代碼: - !$ P {} daterangefrom = NULL && $ P {daterangeto}!= null? 「日期範圍從」+ $ P {daterangefrom} +「和」+ $ P {daterangeto} :$ P {weeks}!= null && $ P {monthy}!= null && $ P {yrs}? 「對於每週」+ $ P {weeks} + $ P {monthy} + $ P {yrs} :$ P {monthy}!= null && $ P {yrs}!= null? 「對於每月」+ $ P {monthy} + $ P {yrs} :$ P {quarter}!= null && $ P {yrs}!= null? 「For quarter」+ $ P {quarter} + $ P {yrs} :$ P {yrs}!= null? 「For annual」+ $ P {yrs}:null – 2012-04-06 09:23:46
錯誤是什麼?我的代碼工作正常 - 我檢查它 – 2012-04-06 09:25:16
錯誤編譯C:\ Documents and Settings \ user \我的文檔\ daterange2.jasper! 編譯異常:[email protected] net.sf.jasperreports.engine.JRException:編譯報表表達式類文件時遇到錯誤:org.codehaus.groovy.control.MultipleCompilationErrorsException:啓動失敗: calculator_daterange_1333704045656_558975:299:期待':',找到''@ line 299,column 289. 1 error –
2012-04-06 09:27:34