Nuclos Jasper formatting: bold, DecimalFormat, REPORT_LOCALE, frames, address, RemoveLineWhenBlank, hyperlink, markup styled, br, LISTAGG, stretch with overflow. |
Language: Deutsch · English
Formatting recipes for JasperReports – bold, number formats, frames/addresses, hyperlinks, markup and line breaks.
Auf dieser Seite |
The bold flag only affects the designer preview – the PDF is not changed. For real bold/italic printing choose the proper font (even though the property is shown struck through).
Choosing bold/italic via the font.
Field content in JasperReports is defined by one Java statement. For formatted decimals:
new java.text.DecimalFormat("#,###,##0.00", java.text.DecimalFormatSymbols.getInstance($P{REPORT_LOCALE})).format($F{betrag}) |
Numbers inside text cannot be formatted automatically. For an English format this hack helps:
new java.text.DecimalFormat("#,##0.00").format($V{zwsumme}.doubleValue()).replace(",", "x").replace(".", ",").replace("x", ".") |
Via Padding and Borders of a text field a line can be shown per side. For the line to grow with the column, the fields must not have a fixed height (see Stretch with overflow).
When a field grows beyond its width, neighbouring fields shift. Fix:
After upload all fields line up.
A frame is a container for further elements (also nested). For an address block the Title band is suitable (first page only); for envelopes leave enough page margin (approx. 50px).
Merge two fields into one address line and remove empty lines:
+ (string concatenation), returning null when a value is missing.Empty lines (e.g. strstrassezusatz) are then removed automatically and the rest are pushed together.
Address block: text field expression.
Link a text field or image – either via the context menu (Hyperlink, type Reference) or directly in the JRXML:
<textField hyperlinkType="Reference"> <reportElement mode="Transparent" x="137" y="14" width="133" height="14"/> <textElement> <font size="11"/> </textElement> <textFieldExpression class="java.lang.String">"www.nuclos.de"</textFieldExpression> <hyperlinkReferenceExpression>"http://www.nuclos.de"</hyperlinkReferenceExpression> </textField> |
With markup you format individual words/paragraphs inside a text field without adding a new field. Set the property markup = styled and use <style> tags:
<style isBold='true' pdfFontName='Helvetica-Bold' >Das ist ein dicker Text </style><style isBold='true' pdfFontName='Helvetica-Bold' size='20'>20 Pixel groß </style><style isItalic='true' isUnderline='true' forecolor='green'> Grüner Text unterstzrichen und schief </style><style isBold='true' pdfFontName='Helvetica-Bold' size='12'>& hallo ich bin ein Sonderzeichen</style> |
Markup fails if the text contains a |
A <br/> in the text produces a line break (field still markup = styled). Example: concatenate a result set in Oracle via LISTAGG() with <br/>:
SELECT listagg(T2x."STRBEZEICHNUNG",'<br/>')
within group (order by T2x."STRBEZEICHNUNG") "strtext"
FROM
Tabelle T1x
WHERE
(
T1x."Tabelle T1x" = Parameter
)) "strtext", |
This property specifies the space already used by other components (not the height of the current element) from which a new page break starts.