在JasperReports中设置文本字段的样式 [英] Style a text field in JasperReports

查看:348
本文介绍了在JasperReports中设置文本字段的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在JasperReports中将内联样式应用于静态文本。可以对文本元素(文本字段)执行相同的操作吗?如果是,怎么做?

I know how to apply inline style to Static Text in JasperReports. Can the same be done for Text Elements (text fields)? If yes, how?

推荐答案

是的,您可以为 textField应用样式 元素。

Yes, you can apply style for textField elements.

报告模板样本:

<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中关于标记的报价属性:

The quote from iReport Ultimate Guide about markup attribute:


标记 属性允许您使用特定标记
语言格式化文本。当您必须打印一些预先格式化的文本
时,这非常有用,即在HTML或RTF中。简单的HTML样式标签
(如粗体和斜体)可用于示例中
突出显示文本的特定块。可能的值如下

This Markup attribute allows you to format the text using a specific markup language. This is extremely useful when you have to print some text that is pre-formatted, that is, in HTML or RTF. Simple HTML style tags (like for bold and for Italic) can be used in example to highlight a particular chunk of the text. The possible values are as follows:



  • 无文字处理执行,文本打印
    与提供的完全一样。
  • 样式

    此标记能够使用一组类似HTML的标记格式化文本,并且在Java环境中非常流行。
    它允许为文本,颜色,背景,样式等块设置特定字体。
    通常以编程方式格式化文本。
  • HTML

    如果您想在报告中打印一些HTML文字,这就是您所需要的,但它的主要用途是格式化文本,所以不要指望能够打印表格或添加
    图像。
  • RTF

    将标记设置为此值,内容将被解释为RTF代码。 RTF是一种以纯文本格式存储的流行文档格式。使用字符串生成了图19中这是RTF格式化的文本这一小段文字:

    {\\\rtf1 \\\\\\\\\\\\\\\\ \ tonttbl {\f0\fswiss\fcharset0
    Arial;} {\f1\fnil\fprq2\fcharset0 Swift;}} {* \generator Msftedit
    5.41.15.1507 ;} \ viewkind4 \uc1 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\实际上是使用简单文字处理器创建的RTF文件。
  • 报告字体

    这是预设字体的名称,将从中获取所有字符属性。
    这个属性已被弃用,它仅用于兼容性
    reason(这就是为什么标签被删除了。为了定义一个
    特定样式的文本来使用整个文档,请使用风格。

  • 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.

    使用标记的样本是这里

    你可以使用 style 用于设置:

  • 公共属性
  • 图形属性
  • 边框和填充属性
  • 文字属性

    You can use style for setting:

  • Common properties
  • Graphics properties
  • Border and padding properties
  • Text properties

    另一个样本是这里

    如果使用< a href =http://dynamicjasper.com/features/ =noreferrer> DynamicJasper API可以在 ar.com.fdvs.dj.domain.builders.ColumnBuilder class:

    In case using DynamicJasper API you can set style with help of ar.com.fdvs.dj.domain.builders.ColumnBuilder class:

    AbstractColumn columnState = ColumnBuilder.getNew()
    .addColumnProperty("state", String.class.getName())
    .addTitle("State").addWidth(new Integer(85))
    .addStyle(detailStyle).addHeaderStyle(headerStyle).build(); 
    

    样本是这里

    如果使用 JasperReports API ,您可以设置样式,例如,使用帮助 net.sf.jasperreports.engine.base .JRBasePrintText class:

    In case using JasperReports API you can set style, for example, with help of net.sf.jasperreports.engine.base .JRBasePrintText class:

    JRPrintText text = new JRBasePrintText(jasperPrint.getDefaultStyleProvider());
    text.setStyle(boldStyle);
    

    样本是此处

    这篇关于在JasperReports中设置文本字段的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆