【问题标题】:iReport Cell Spanning in Table Component表格组件中的 iReport 单元格跨度
【发布时间】:2012-12-06 08:05:05
【问题描述】:

我正在使用 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 值吗?我将&lt;printWhenExpression&gt;&lt;![CDATA[$V{supplyGroup_COUNT} == 1 || $P{hasPageBreak}.equals("1"))]]&gt;&lt;/printWhenExpression&gt; 放入表的文本字段,但编译器抱怨无法找到参数hasPageBreak。目前,我只计算表中的项目,并在 $V{supplyGroup_COUNT} == 20 并且如果有新页面时显示另一个“文本”。

3.有没有办法在物品达到一定数量后强制打破桌子?我在表格后面有一些文字。我希望始终将表格的至少一部分(末尾)与以下文本一起保留。还是我必须使用两个单独的表?

【问题讨论】:

  • Is there a way to center the COLUMN_0 value - 你是什么意思?
  • @AlexK 我编辑了我的帖子。我的意思是 COLUMN_0 值的垂直对齐方式。在您对 user1264222 问题的解决方案中,您使用了表达式 $V{supplyGroup_COUNT} == 1,因此该值被写入第一个单元格。我想把它显示在中间。
  • 换句话说,您希望在某些情况下(条件样式)将样式(垂直对齐)应用于字段。我说的对吗?
  • @AlexK 是的,我添加了一些图片来说明我的问题。

标签: java jasper-reports ireport xmltable


【解决方案1】:

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

<textElement verticalAlignment="Middle"/>

我使用一种风格

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

其他两个我不确定(欢迎投稿)

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

3) 乐队上的Split Type 可能会有所帮助,但如果“一些文本”是一个单独的对象,我不相信你可以阻止它成为孤儿

希望有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    • 1970-01-01
    • 2011-10-21
    • 1970-01-01
    • 2011-08-26
    • 2022-10-23
    相关资源
    最近更新 更多