0
我正在使用iReport以在表格中显示来自net.sf.jasperreports.engine.data.JRTableModelDataSource
的数据。我使用TableModelDataSource,因为我必须使用Java作为数据源。iReport单元格跨越表格组件
我现在得到了下面的代码,这是工作的罚款:
<?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.是否有办法强制一个表打破一定数量的项目后?我在桌子后面有一些文字。我希望总是至少有一部分(结束)和下面的文字。或者我必须使用两个单独的表?
'有没有办法让COLUMN_0值居中? - 你是什么意思? –
@AlexK我编辑了我的文章。我的意思是COLUMN_0值的垂直对齐。在针对user1264222问题的解决方案中,您使用表达式“$ V {supplyGroup_COUNT} == 1”,以便将值写入第一个单元格中。我想在中间显示它。 – Torsten
换句话说,在某些情况下(条件样式),您想要将样式(垂直对齐)应用于该字段。我对吗? –