jasper 报告中的垂直文本对齐方式

bin*_*ter 5 jasper-reports

我在 jasper 报告中有一个表格,我需要该表格中某些单元格的内容垂直对齐。 我正在尝试使用 iReport 编辑报告。

在 iReport 中,我可以进入单元格的属性并看到垂直对齐设置为“中间”。此外,当我直接查看 XML 时(见下文),我可以看到textElement标记具有 VerticalAlignment="Middle" 属性。

据我所知,文本应该在其小框中垂直对齐,但它无法正确对齐。

我希望有在 jasper 报告中垂直对齐内容经验的人能够指出我做错了什么。 非常感谢。

<textField 
  isStretchWithOverflow="false"
  isBlankWhenNull="true" 
  evaluationTime="Now" 
  hyperlinkType="None"
  hyperlinkTarget="Self" >

  <reportElement
    x="227"
    y="0"
    width="31"
    height="14"
    key="textField-4"/>

  <box>
    <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
    <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
    <bottomPen lineWidth="0.0" lineColor="#000000"/>
    <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
  </box>

  <textElement textAlignment="Center" verticalAlignment="Middle">
    <font fontName="Times New Roman" pdfFontName="Times-Roman" size="8"/>
  </textElement>

  <textFieldExpression class="java.lang.String"><![CDATA[$F{someVariableName}]]></textFieldExpression>
</textField>
Run Code Online (Sandbox Code Playgroud)

因此,需要明确的是,我的报告中的内容是这样的:

|--------|
|  text  |
|        |
|        |
|--------|
Run Code Online (Sandbox Code Playgroud)

想要的是这样的:

|--------|
|        |
|  text  |
|        |
|--------|
Run Code Online (Sandbox Code Playgroud)

use*_*935 2

以下是我解决此问题的方法(iReport 3.7.6):

在“设计器”选项卡中:

  1. 右键单击静态文本框
  2. 选择“内边距和边框”
  3. 在弹出框中,将“Top”或“Bottom”值增加,例如5,然后单击“确定”以查看此更改的结果。

正如您所看到的,这将允许您按照您想要的方式放置静态文本。

如果您只能在 XML 中进行更改,则更改在 XML 中的显示方式如下:

    <box topPadding="4"/>
Run Code Online (Sandbox Code Playgroud)

带静态文本代码块的示例:

    <staticText>
    <reportElement positionType="Float" mode="Opaque" x="14" y="27" width="118" height="14" forecolor="#FFFFFF" backcolor="#909090"/>
    <box topPadding="4"/>
    <textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" lineSpacing="Single" markup="none">
    <font fontName="Arial" size="7" isBold="true" isUnderline="false" isStrikeThrough="false" isPdfEmbedded="false"/>
    </textElement>
    <text><![CDATA[SAMPLE TEXT SAMPLE TEXT]]></text>
    </staticText>
Run Code Online (Sandbox Code Playgroud)

  • 感谢您的回答!不幸的是,我无法测试/尝试它,因为值得庆幸的是,自 2010 年以来我没有接触过 jasper 或 iReport。但是,如果它对你有用,我想这对我来说就足够了。 (2认同)