Я знаю, как применить встроенный стиль к статическому тексту в JasperReports. Можно ли сделать то же самое для текстовых элементов (текстовых полей)? Если да, то как?
Стиль текстового поля в JasperReports
Ответы (1)
Да, вы можете применить стиль к элементам textField
.
iReport с использованием
Образец шаблона отчета:
<jasperReport ..>
<style name="ColoredField" style="Default" forecolor="#FF0000">
<conditionalStyle>
<style/>
</conditionalStyle>
</style>
...
<detail>
<band height="52" splitType="Stretch">
<!--Using the style declared in this template-->
<textField>
<reportElement key="textWithStyle" style="ColoredField" mode="Opaque" x="0" y="10" width="100" height="20"/>
<textElement/>
<textFieldExpression><![CDATA[$F{TASKS_SERIES}]]></textFieldExpression>
</textField>
<!--Basic formatting (set font and indent) using-->
<textField>
<reportElement key="textWithoutStyle" x="100" y="10" width="100" height="20"/>
<textElement>
<font fontName="Arial" size="14" isBold="true" isItalic="true" isUnderline="false"/>
<paragraph leftIndent="10"/>
</textElement>
<textFieldExpression><![CDATA[$F{TASKS_TASK}]]></textFieldExpression>
</textField>
<!--Markup using: styled-->
<textField>
<reportElement x="200" y="10" width="590" height="42"/>
<textElement markup="styled"/>
<textFieldExpression><![CDATA["The static text without any format.\nThe field's data with bold format<style isBold='true'>:" + $F{TASKS_SUBTASK} + "</style>\n<style isBold='true' isItalic='true' isUnderline='true'>The static underlined text with bold and italic format</style>"]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
Цитата из iReport Ultimate Guide об атрибуте markup
:
Этот атрибут
Markup
позволяет форматировать текст с использованием определенного языка разметки. Это чрезвычайно полезно, когда вам нужно напечатать предварительно отформатированный текст, то есть в формате HTML или RTF. Простые теги стиля HTML (например, для жирного шрифта и курсива) можно использовать, например, для выделения определенного фрагмента текста. Возможные значения следующие:None
No processing on the text is performed, and the text is printed exactly like it is provided.Styled
This markup is capable to format the text using a set of HTML-like tags and it is pretty popular in the Java environments. It allows to set a specific font for chunks of text, color, background, style and so on. It's often good enough to format the text programmatically.HTML
If you want to print some HTML text into your report, this is what you need, but it's primary use is to format text, so don't expect to be able to print tables or add images.RTF
Setting the markup to this value, the content will be interpreted as RTF code. RTF is a popular document format stored in pure text. The little piece of text saying “this is a text formatted in RTF” in Illustration 19 has been generated using the string:
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}{\f1\fnil\fprq2\fcharset0 Swift;}} {*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\f0\fs20 This is a text \f1\fs52 formatted \f0\fs20 in RTF\par }
The string is actually an RTF file created using a simple word processor.Report font
This is the name of a preset font, from which will be taken all the character properties. This attribute is deprecated and it is there only for compatibility reason (that's why it the label is strukethrough. In order to define a particular style of text to use all over your document, use a style.
Пример использования markup
находится здесь.
You can use style
for setting:
Другой образец находится здесь.
API DynamicJasper с использованием
В случае использования DynamicJasper API вы можете установить стиль с помощью ar.com.fdvs.dj.domain.builders.ColumnBuilder:
AbstractColumn columnState = ColumnBuilder.getNew()
.addColumnProperty("state", String.class.getName())
.addTitle("State").addWidth(new Integer(85))
.addStyle(detailStyle).addHeaderStyle(headerStyle).build();
Образец находится здесь.
API JasperReports с использованием
В случае использования JasperReports API можно задать стиль, например, с помощью net.sf.jasperreports.engine.base .JRBasePrintText class :
JRPrintText text = new JRBasePrintText(jasperPrint.getDefaultStyleProvider());
text.setStyle(boldStyle);
Образец находится здесь.
markup
. Еще раз спасибо
- person Alex K; 15.11.2011
<reportElement style="Calibri" ...
не работает.
- person zygimantus; 06.10.2016