如何根据参数构造标题标题?
例如,我有一份按日期、每周、月份和年份的报告。我有一个参数,但我不知道如何在标题中显示它。
我想要的是:
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>