[英]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.