0

我正在使用 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>

我现在需要知道的是

  1. 有没有办法将 COLUMN_0 值垂直居中(将垂直对齐设置为“中心”)。我想它必须像这样if $V{supplyGroup_COUNT} == $V{supplyGroup_SIZE}/2。我在“实际”下显示了表格,但我希望它动态地看起来像“目标”。 垂直对齐
  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.有没有办法在物品达到一定数量后强制打破桌子?我在表格后面有一些文字。我希望始终将表格的至少一部分(末尾)与以下文本一起保留。还是我必须使用两个单独的表?

打破桌子

4

1 回答 1

0

1)是的,您可以垂直对齐表格单元格内容

<textElement verticalAlignment="Middle"/>

我用一种风格

<style name="table_TD" vAlign="Middle" />

我不确定其他两个(欢迎贡献)

2) isReprintHeaderOnEachPage 适用于组标题,但我不确定是否适用于表格?(我经常使用缩减的子报表来代替表格。)

3)带上的拆分类型可能会有所帮助,但如果“某些文本”是一个单独的对象,我不相信你可以阻止它成为孤立对象

希望有帮助

于 2013-01-09T20:58:33.897 回答