【问题标题】:Dynamically adding textField in JasperReports在 JasperReports 中动态添加 textField
【发布时间】:2016-12-17 00:37:11
【问题描述】:

有没有办法在 Jasper 报告中将 textFields 动态添加到 columnFooter。

我有可能需要使用的情况:

  <columnFooter>
      <band height="21" splitType="Stretch">
        <textField isStretchWithOverflow="true">
            <reportElement x="0" y="0" width="50" height="21"/>
            <textElement textAlignment="Center" verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA["Example text...."]]></textFieldExpression>
        </textField>
      </band>

      <columnFooter>
      <band height="42" splitType="Stretch">
        <textField isStretchWithOverflow="true">
            <reportElement x="0" y="0" width="50" height="21"/>
            <textElement textAlignment="Center" verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA["Example text...."]]></textFieldExpression>
        </textField>            <textField isStretchWithOverflow="true">
            <reportElement x="0" y="0" width="50" height="21"/>
            <textElement textAlignment="Center" verticalAlignment="Middle"/>
            <textFieldExpression><![CDATA["More example text...."]]></textFieldExpression>
        </textField>
      </band>

(或添加任意数量的文本字段。由于我不知道将添加多少,我需要以某种方式动态调整乐队的大小)我正在寻找一种在 Java 中动态执行此操作而不必对其进行硬编码的方法在 jrxml 文件中。谢谢

【问题讨论】:

标签: java jasper-reports


【解决方案1】:

使用第二种方法在 textFields 上设置 PrintWhenExpression 并在此 textFields 的属性上设置“删除空白行”复选框。

【讨论】:

  • 叹息..它真的需要动态..在那个特定的例子中,我有两个文本字段,但它真的可以是任何数字......关键是,我不知道,而且当我输入 x 数量的 textFields 时,需要一种方法来自动调整乐队的大小
【解决方案2】:

如果您的报告是作为 JRDesign 动态创建的,您可以使用以下内容:

JRDesignBand band = (JRDesignBand) jasperDesign.getColumnFooter();
        JRDesignTextField textField = new JRDesignTextField();
        textField.setX(0);
        textField.setY(0);
        band.addElement(textField);

【讨论】:

    【解决方案3】:

    很抱歉,在使用 JR Java API 多年后,我感觉它是为在文档的固定布局上打印而设计的。 对您的情况有什么帮助:如果您知道可能出现的最大字段数,只需将它们全部添加到带区中,并将每个字段的“空白时删除行”标志设置为 true。它将折叠未使用的字段。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-06
      • 1970-01-01
      • 2020-10-22
      • 2011-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-17
      相关资源
      最近更新 更多