Domanda

I'm new in Jasper Reports. I use iReport 4.5 in NetBeans. I need create some text and insert into text new variable. All works, but new line doesn't create. Tell me please, how to solve it? Thanks!

`<?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_report_template" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="50" bottomMargin="50">
    <property name="ireport.zoom" value="1.3310000000000004"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <parameter name="ReportTitle" class="java.lang.String"/>
    <parameter name="Author" class="java.lang.String"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="country" class="java.lang.String">
        <fieldDescription><![CDATA[country]]></fieldDescription>
    </field>
    <field name="name" class="java.lang.String">
        <fieldDescription><![CDATA[name]]></fieldDescription>
    </field>
    <title>
        <band height="240" splitType="Stretch">
            <textField isBlankWhenNull="true" bookmarkLevel="1">
                <reportElement x="0" y="0" width="515" height="27"/>
                <textElement textAlignment="Center">
                    <font size="10" pdfEncoding="Cp1251"/>
                </textElement>
                <textFieldExpression>
                <![CDATA["Some text "+ $P{ReportTitle} +" my name +"<br/>"+ is "]]>
                </textFieldExpression>
                <anchorNameExpression><![CDATA["Title"]]></anchorNameExpression>
            </textField>
        </band>
    </title>
    <columnHeader>
        <band height="24" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="21" splitType="Stretch"/>
    </detail>
</jasperReport>`
È stato utile?

Soluzione

OlliZi answer is not valid if a parameter contains a <br>, and Kamel's answer is not valid if you don't use the same iReport version... So this is the universal answer in the .jrxml file.

Add markup="html" to the used style or in the reportElement, without using a specific editor. Very usefull for fast and compatible fix.

<textField>
    <reportElement x="0" y="0" width="100" height="50" markup="html" />
    <textFieldExpression>
        <![CDATA["Some text "+ $P{ReportTitle} +" my name +"<br/>"+ is "]]>
    </textFieldExpression>
</textField>

Or, if you use a style:

<style name="myStyle" markup="html" />

<textField>
    <reportElement x="0" y="0" width="100" height="50" style="myStyle" />
    <textFieldExpression>
        <![CDATA["Some text "+ $P{ReportTitle} +" my name +"<br/>"+ is "]]>
    </textFieldExpression>
</textField>

Altri suggerimenti

You can also use following string:

"Some text " + $P{ReportTitle} + " my name " + "\n" + " is ".

Or shorter:

"Some text " + $P{ReportTitle} + " my name \n is ".

Set Markup property to html, and make your string like this :

"Some text " + $P{ReportTitle} + " my name " + "<br>" + " is ".

set Stretch with overflow property to true

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top