1

I have a simple report like this:

enter image description here

I pass the info formatted like this:

{ image deleted }

But when I see the report I see something completely shuffle or unformatted like this:

enter image description here

I want the text formatted like I pass from Java. What I am doing wrong?

Update

The periodoDisfrutado is a field from type java.lang.String and I pass from my Java a java.lang.String:

enter image description here

My Java class the method which is send the data to the report:

enter image description here

My XML file is

<group name="empleado">
    <groupExpression><![CDATA[$F{empleado}]]></groupExpression>
    <groupHeader>
        <band height="117">
            <textField>
                <reportElement x="7" y="8" width="547" height="20" forecolor="#FF0000"/>
                <textElement>
                    <font isBold="true"/>
                </textElement>
                <textFieldExpression class="java.lang.String"><![CDATA["Empleado: " + $F{empleado}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="7" y="33" width="148" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA["Dias de Vacaciones/Año: " + $F{diasTotal}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="161" y="33" width="119" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA["Dias disfrutados: " + $F{gastados}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="281" y="33" width="105" height="20"/>
                <textElement/>
                <textFieldExpression class="java.lang.String"><![CDATA["Dias restantes: " + $F{restantes}]]></textFieldExpression>
            </textField>
            <textField isStretchWithOverflow="true" isBlankWhenNull="false">
                <reportElement x="176" y="59" width="378" height="56"/>
                <textElement textAlignment="Left"/>
                <textFieldExpression class="java.lang.String"><![CDATA[$F{periodoDisfrutado}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="7" y="59" width="169" height="20"/>
                <textElement/>
                <text><![CDATA[Periodos de vacaciones disfrutados:]]></text>
            </staticText>
        </band>
    </groupHeader>
</group>
6
  • What datasource are you using?
    – Alex K
    Jan 21, 2016 at 13:26
  • 1
    It is better to post your code (sample jrxml + Java code)
    – Alex K
    Jan 21, 2016 at 13:27
  • The datasource is just a plain Java Class with some fields. See my edited question thanks a lot Jan 21, 2016 at 13:55
  • Pass the relavant part of the jrxml file Jan 21, 2016 at 14:47
  • It seems that all your "unformatted" text is in a single $field, so jasper format it as text, maybe you need to restructure data as datasource and use a subreport... Jan 21, 2016 at 14:49

1 Answer 1

1

It is as I suspected you are passing a String with page break, spaces and maybe tabs. Jasper report will not try to format as table, it will simply display your string and depending on font type, etc you will have different result.

If you like to create a table format instead of a String you need to pass a JRDataSource, and use for example a subreport to display the data.

Note: This will also greatly improve your export to excel.

The best way to setup this datasource depends on what kind of current datasource you are using, where are the $F{periodoDisfrutado} coming from?

2
  • i developed a subreport and works great thanks a lot petter and best regars from Venezuela.. Jan 22, 2016 at 13:21
  • sorry it should be etc. (et cetera, eccetera)and so on. Jan 22, 2016 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.