[英]Dynamically adding textField in JasperReports
有没有一种方法可以在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>
(或添加任意数量的textFields。由于我不知道要添加多少个textField,因此我需要以某种方式动态调整带的大小)我正在寻找一种方法来在Java中动态执行此操作,而不必在jrxml中对其进行硬编码文件。 谢谢
使用第二种方法在textFields上设置PrintWhenExpression并在此textFields的属性上设置“在空白时删除行”复选框。
如果您的报告是作为JRDesign动态创建的,则可以使用以下方法:
JRDesignBand band = (JRDesignBand) jasperDesign.getColumnFooter();
JRDesignTextField textField = new JRDesignTextField();
textField.setX(0);
textField.setY(0);
band.addElement(textField);
我很遗憾地说,但是经过多年与JR Java API的合作,我感到它旨在打印在文档的固定布局上。 在您的情况下可能有用的方法:如果您知道可能出现的最大字段数,只需将它们全部添加到波段,然后将每个字段的“空白时删除行”标志设置为true。 它将折叠未使用的字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.