我正在使用 iReport 来显示来自net.sf.jasperreports.engine.data.JRTableModelDataSource
表格中的数据。我使用的是 TableModelDataSource,因为我必须使用 Java 作为数据源。
我现在得到了以下代码,它工作正常:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="controltest" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.3310000000000022"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="276"/>
<property name="ireport.callouts" value="##Wed Dec 05 08:22:05 CET 2012"/>
<subDataset name="plantsResultTable">
<field name="COLUMN_0" class="java.lang.String"/>
<field name="COLUMN_1" class="java.lang.String"/>
<field name="COLUMN_2" class="java.lang.String"/>
<field name="COLUMN_3" class="java.lang.String"/>
<field name="COLUMN_4" class="java.lang.String"/>
<field name="COLUMN_5" class="java.lang.String"/>
<field name="readActualSupply" class="java.lang.String"/>
<group name="supplyGroup">
<groupExpression><![CDATA[$F{readActualSupply}]]></groupExpression>
</group>
</subDataset>
<field name="remotelyControlledSupply" class="java.lang.String"/>
<field name="thirdPartyAccess" class="java.lang.String"/>
<field name="plantsResultTable" class="net.sf.jasperreports.engine.JRDataSource"/>
<background>
<band/>
</background>
<pageHeader>
<band/>
</pageHeader>
<detail>
<band height="675">
<frame>
<reportElement x="0" y="250" width="555" height="239"/>
<componentElement>
<reportElement key="table 2" x="0" y="17" width="555" height="222"/>
<jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
<datasetRun subDataset="plantsResultTable">
<dataSourceExpression><![CDATA[$F{plantsResultTable}]]></dataSourceExpression>
</datasetRun>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_0]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField pattern="">
<reportElement x="0" y="0" width="90" height="20">
<printWhenExpression><![CDATA[$V{supplyGroup_COUNT} == 1]]></printWhenExpression>
</reportElement>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_0}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_1]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_1}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_2]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_2}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_3]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_3}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_4]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_4}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="90">
<jr:columnHeader height="30">
<staticText>
<reportElement x="0" y="0" width="90" height="30"/>
<textElement/>
<text><![CDATA[COLUMN_5]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell height="20">
<textField>
<reportElement x="0" y="0" width="90" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{COLUMN_5}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:table>
</componentElement>
</frame>
</band>
</detail>
<columnFooter>
<band/>
</columnFooter>
<pageFooter>
<band/>
</pageFooter>
<summary>
<band/>
</summary>
</jasperReport>
我现在需要知道的是
- 有没有办法将 COLUMN_0 值垂直居中(将垂直对齐设置为“中心”)。我想它必须像这样
if $V{supplyGroup_COUNT} == $V{supplyGroup_SIZE}/2
。我在“实际”下显示了表格,但我希望它动态地看起来像“目标”。 - 如果表有分页符,有没有办法打印另一个 COLUMN_0 值。也就是说,表格从第 1 页开始,并在第 2 页结束。我可以在第 1 页和第 2 页上打印 COLUMN_0 值吗?我在
<printWhenExpression><![CDATA[$V{supplyGroup_COUNT} == 1 || $P{hasPageBreak}.equals("1"))]]></printWhenExpression>
表的 textField 中添加了一个,但编译器抱怨无法找到参数 hasPageBreak。目前,我只计算表中的项目,如果 $V{supplyGroup_COUNT} == 20 并且如果有新页面,则放置另一个可见的“文本”。
3.有没有办法在物品达到一定数量后强制打破桌子?我在表格后面有一些文字。我希望始终将表格的至少一部分(末尾)与以下文本一起保留。还是我必须使用两个单独的表?