【问题标题】:How to set the textfield component position based on the other text(text come from DB, don't know the length) in ireport如何根据ireport中的其他文本(文本来自数据库,不知道长度)设置文本字段组件位置
【发布时间】:2019-08-31 00:47:42
【问题描述】:

我必须用 JasperReports 做这样的事情:

大家好,我是xxxxxxxxxxxx,在yyyyyy

发帖提问

在上面的文本中 xxxxxxxxxxxx 是动态的,它来自数据库,所以我不知道该字符串的长度,但其余的文本(从逗号,) 应在此之后立即出现。 xxxxxxxxxxx和逗号(,)之间不能有空格。

仅供参考:这里我使用了 4 个文本字段。

【问题讨论】:

  • 添加这样的文本字段"my name is"+$F{name}+", posting a question in "+F{year}
  • 谢谢 Mani,我第一次尝试像这样(一个 TextField 中的总文本)。但请注意动态文本(xxxxx..)应为粗体。在单个 TextField 中,我无法应用不同的样式。这就是我采用 4 个单独的 TextField 的原因。我尝试了以下解决方案但没有用.. stackoverflow.com/questions/16294372/… 谢谢。

标签: jasper-reports


【解决方案1】:

尝试为 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'>:Mani, here im bold</style>\n<style isBold='true' isItalic='true' isUnderline='true'>The static underlined text with bold and italic format</style>"]]></textFieldExpression>
</textField>

在这里根据您的要求添加您的字段和样式。

有关 Textfield 标记的完整参考,请访问 this SO Answer

【讨论】:

    【解决方案2】:

    尝试创建一个像“name”这样的参数,而不是你的文本字段的表达式应该是这样的:

    "Hello Everyone, my name is " + $P{name} + "....."
    

    这应该可行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-29
      • 2020-03-20
      • 1970-01-01
      相关资源
      最近更新 更多