【问题标题】:iReport: Getting multiple copies of table in detail bandiReport:在详细信息带中获取表格的多个副本
【发布时间】:2016-03-10 16:38:11
【问题描述】:

我是iReport 的新成员。所以我想根据数据做一个简单的报告。

我的问题是,当我的行小于细节带的大小时,整个表格会在细节带中重复,我不想再这样了。如果我的行大约是 5 行,那么同一张表在详细带中被复制 4 次,不仅是表格,而且我放在详细带中的每一个东西。它会不断重复,直到出现详细的频带限制。

我是不是犯了一些错误,或者我必须在iReport 中设置一些细节带的属性?

请帮助我的朋友。提前致谢。

这是生成的结果:

这是我的 jrxml 代码:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport language="groovy" bottomMargin="20" topMargin="20" rightMargin="20" leftMargin="20" columnWidth="555"
              whenNoDataType="AllSectionsNoDetail" pageHeight="842" pageWidth="595" name="test"
              xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns="http://jasperreports.sourceforge.net/jasperreports">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="0"/>
    <style name="table">
        <box>
            <pen lineColor="#000000" lineWidth="1.0"/>
        </box>
    </style>
    <style name="table_TH" backcolor="#F0F8FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table_CH" backcolor="#BFE1FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table_TD" backcolor="#FFFFFF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 1">
        <box>
            <pen lineColor="#000000" lineWidth="1.0"/>
        </box>
    </style>
    <style name="table 1_TH" backcolor="#F0F8FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 1_CH" backcolor="#BFE1FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 1_TD" backcolor="#FFFFFF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 2">
        <box>
            <pen lineColor="#000000" lineWidth="1.0"/>
        </box>
    </style>
    <style name="table 2_TH" backcolor="#F0F8FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 2_CH" backcolor="#BFE1FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 2_TD" backcolor="#FFFFFF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 3">
        <box>
            <pen lineColor="#000000" lineWidth="1.0"/>
        </box>
    </style>
    <style name="table 3_TH" backcolor="#F0F8FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 3_CH" backcolor="#BFE1FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 3_TD" backcolor="#FFFFFF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 4">
        <box>
            <pen lineColor="#000000" lineWidth="1.0"/>
        </box>
    </style>
    <style name="table 4_TH" backcolor="#F0F8FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 4_CH" backcolor="#BFE1FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 4_TD" backcolor="#FFFFFF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 5">
        <box>
            <pen lineColor="#000000" lineWidth="1.0"/>
        </box>
    </style>
    <style name="table 5_TH" backcolor="#F0F8FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 5_CH" backcolor="#BFE1FF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <style name="table 5_TD" backcolor="#FFFFFF" mode="Opaque">
        <box>
            <pen lineColor="#000000" lineWidth="0.5"/>
        </box>
    </style>
    <subDataset name="a">
        <parameter name="sem" class="java.lang.String">
            <defaultValueExpression>
                <![CDATA[]]>
            </defaultValueExpression>
        </parameter>
        <queryString>
            <![CDATA[select final."M" as "ENROLLMENT",sem_batch.sem,sem_batch.batch,final."N" as "TTL_WKDY",final."O" as "PRESENT",round(((100*"O")/"N"),2) as "PERCENTAGE" from sem_batch, (select m."Std_id" as "M",l."Batch" as "L",l."Btch" as "N",m."Std" as "O" from (select count(b.batch_id) as "Btch",b.batch_id as "Batch" from batch_wkday b where b.batch_id like $P{sem} group by batch_id) l, (select count(a.std_id) as "Std",a.std_id as "Std_id",s.batch_id as "Batch" from attendance a,student_detail s where a.std_id=s.std_id and s.batch_id like $P{sem} group by a.std_id,s.batch_id) m where l."Batch"=m."Batch") final where final."L"=sem_batch.batch_id]]>
        </queryString>
        <field name="ENROLLMENT" class="java.math.BigDecimal"/>
        <field name="SEM" class="java.math.BigDecimal"/>
        <field name="BATCH" class="java.lang.String"/>
        <field name="TTL_WKDY" class="java.math.BigDecimal"/>
        <field name="PRESENT" class="java.math.BigDecimal"/>
        <field name="PERCENTAGE" class="java.math.BigDecimal"/>
        <group name="ENROLLMENT">
            <groupExpression>
                <![CDATA[$F{ENROLLMENT}]]>
            </groupExpression>
        </group>
    </subDataset>
    <parameter name="SEM" class="java.lang.String"/>
    <queryString>
        <![CDATA[select * from sem_batch]]>
    </queryString>
    <field name="SEM" class="java.math.BigDecimal"/>
    <field name="BATCH" class="java.lang.String"/>
    <field name="BATCH_ID" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band splitType="Stretch" height="69">
            <staticText>
                <reportElement height="53" width="421" y="0" x="68"/>
                <textElement markup="none" textAlignment="Center">
                    <font size="22"/>
                </textElement>
                <text>
                    <![CDATA[ATTENDANCE - CLASS ]]>
                </text>
            </staticText>
        </band>
    </title>
    <pageHeader>
        <band splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band splitType="Stretch" height="61">
            <staticText>
                <reportElement height="20" width="53" y="0" x="0"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <text>
                    <![CDATA[SEM]]>
                </text>
            </staticText>
            <staticText>
                <reportElement height="20" width="53" y="20" x="0"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <text>
                    <![CDATA[DATE]]>
                </text>
            </staticText>
            <staticText>
                <reportElement height="20" width="10" y="0" x="58"/>
                <textElement/>
                <text>
                    <![CDATA[:]]>
                </text>
            </staticText>
            <staticText>
                <reportElement height="20" width="10" y="20" x="58"/>
                <textElement/>
                <text>
                    <![CDATA[:]]>
                </text>
            </staticText>
            <textField pattern="dd/MM/yyyy">
                <reportElement height="20" width="100" y="20" x="68"/>
                <textElement/>
                <textFieldExpression>
                    <![CDATA[new java.util.Date()]]>
                </textFieldExpression>
            </textField>
            <textField>
                <reportElement height="20" width="100" y="0" x="68"/>
                <textElement/>
                <textFieldExpression>
                    <![CDATA[$P{SEM}]]>
                </textFieldExpression>
            </textField>
        </band>
    </columnHeader>
    <detail>
        <band splitType="Stretch" height="125">
            <componentElement>
                <reportElement height="50" width="360" y="0" x="35" style="table 5" key="table 5"/>
                <jr:table
                        xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"
                        xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components">
                    <datasetRun subDataset="a">
                        <datasetParameter name="sem">
                            <datasetParameterExpression>
                                <![CDATA[$P{SEM}+'%']]>
                            </datasetParameterExpression>
                        </datasetParameter>
                        <connectionExpression>
                            <![CDATA[$P{REPORT_CONNECTION}]]>
                        </connectionExpression>
                    </datasetRun>
                    <jr:column width="118">
                        <jr:columnHeader height="23" style="table 5_CH" rowSpan="1">
                            <staticText>
                                <reportElement height="20" width="118" y="0" x="0"/>
                                <textElement textAlignment="Center">
                                    <font size="14" isBold="false"/>
                                </textElement>
                                <text>
                                    <![CDATA[ENROLLMENT]]>
                                </text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="20" style="table 5_TD" rowSpan="1">
                            <textField>
                                <reportElement height="20" width="118" y="0" x="0"/>
                                <textElement textAlignment="Center">
                                    <font size="10" isBold="false"/>
                                </textElement>
                                <textFieldExpression>
                                    <![CDATA[$F{ENROLLMENT}]]>
                                </textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:columnHeader height="23" style="table 5_CH" rowSpan="1">
                            <staticText>
                                <reportElement height="20" width="90" y="0" x="0"/>
                                <textElement textAlignment="Center">
                                    <font size="14"/>
                                </textElement>
                                <text>
                                    <![CDATA[SEM]]>
                                </text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="20" style="table 5_TD" rowSpan="1">
                            <textField>
                                <reportElement height="20" width="90" y="0" x="0"/>
                                <textElement textAlignment="Center">
                                    <font size="10"/>
                                </textElement>
                                <textFieldExpression>
                                    <![CDATA[$F{SEM}]]>
                                </textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:columnHeader height="23" style="table 5_CH" rowSpan="1">
                            <staticText>
                                <reportElement height="20" width="90" y="0" x="0"/>
                                <textElement textAlignment="Center">
                                    <font size="14"/>
                                </textElement>
                                <text>
                                    <![CDATA[BATCH]]>
                                </text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="20" style="table 5_TD" rowSpan="1">
                            <textField>
                                <reportElement height="20" width="90" y="0" x="0"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression>
                                    <![CDATA[$F{BATCH}]]>
                                </textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:columnHeader height="23" style="table 5_CH" rowSpan="1">
                            <staticText>
                                <reportElement height="20" width="90" y="0" x="0"/>
                                <textElement textAlignment="Center">
                                    <font size="14"/>
                                </textElement>
                                <text>
                                    <![CDATA[PRESENT]]>
                                </text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="20" style="table 5_TD" rowSpan="1">
                            <textField>
                                <reportElement height="20" width="90" y="0" x="0"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression>
                                    <![CDATA[$F{PRESENT}]]>
                                </textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90">
                        <jr:columnHeader height="23" style="table 5_CH" rowSpan="1">
                            <staticText>
                                <reportElement height="20" width="90" y="0" x="0"/>
                                <textElement textAlignment="Center">
                                    <font size="14"/>
                                </textElement>
                                <text>
                                    <![CDATA[PERCENTAGE]]>
                                </text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="20" style="table 5_TD" rowSpan="1">
                            <textField>
                                <reportElement height="20" width="90" y="0" x="0"/>
                                <textElement textAlignment="Center"/>
                                <textFieldExpression>
                                    <![CDATA[$F{PERCENTAGE}]]>
                                </textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
    <columnFooter>
        <band splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band splitType="Stretch" height="54">
            <textField>
                <reportElement height="20" width="100" y="16" x="227"/>
                <textElement textAlignment="Center"/>
                <textFieldExpression>
                    <![CDATA[$V{PAGE_NUMBER}]]>
                </textFieldExpression>
            </textField>
        </band>
    </pageFooter>
    <summary>
        <band splitType="Stretch" height="42"/>
    </summary>
</jasperReport>

【问题讨论】:

  • 嗨,欢迎来到 SO。你能解释一下你是如何设计你的报告格式的吗?图片或带有一些解释的 JRXML 文件会很有帮助。
  • 是的,当然...这里我附上文件,以便您也可以看到 jrxml 文件以及 pdf 文件...
  • 我无法读取您的 jrxml 文件,它不适用于 priview。您可以使用代码块将其直接粘贴到您的帖子中。
  • 查看这篇文章..link

标签: jasper-reports ireport


【解决方案1】:

您应该将 table 组件放入 Title 波段(例如,放入 Summary 波段) .不属于 Detail 乐队。

【讨论】:

  • 当我这样做时,我的报告预览中只有一个很大的空间。我能做些什么来防止这种情况发生?
【解决方案2】:

选择表格属性并添加 printWhenExpression$V{REPORT_COUNT} == 1 现在避免在您的 ireport 中重复表值。

【讨论】:

    【解决方案3】:

    根据之前的回答响应,我可以使用“详细信息”部分中的表格并设置以下属性以避免在文档末尾生成重复页面或空白页面。

    Detail Band -> 将 Print When Expression 设置为 $V{REPORT_COUNT} == 1 表格元素 -> 设置 Print When Expression $V{REPORT_COUNT} == 1

    【讨论】:

      【解决方案4】:

      嘿,我解决了我的问题。如果在主查询中返回多行,那么就会发生这种情况。尝试给出返回不超过一行的查询。就像“从双重中选择 1”。这个解决方案解决了我的问题。

      【讨论】:

      • 在哪里写这个“select 1 from dual”?
      • 将此查询写入主报表查询。您可以在右键单击报告后找到该查询编辑器,然后转到编辑查询选项。
      猜你喜欢
      • 1970-01-01
      • 2012-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多