How to prevent repetition of data display in report?

爱⌒轻易说出口 提交于 2020-01-21 15:20:19

问题


Sample Report - Design

Sample Report - Preview

XML Code File

<?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="report2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="82a3ce80-bdcd-4d51-8f21-e72b3f438b53">
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
        <conditionalStyle>
            <conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
            <style backcolor="#EFF7FF"/>
        </conditionalStyle>
    </style>
    <style name="table 1">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table 1_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
        <conditionalStyle>
            <conditionExpression><![CDATA[new Boolean($V{REPORT_COUNT}.intValue()%2==0)]]></conditionExpression>
            <style backcolor="#EFF7FF"/>
        </conditionalStyle>
    </style>
    <subDataset name="dataset1" uuid="70653a81-8d48-4edd-b72f-20f769f51aea">
        <queryString language="SQL">
            <![CDATA[SELECT
     schooldetails.`ID` AS schooldetails_ID,
     schooldetails.`Name` AS schooldetails_Name,
     schooldetails.`Boardtype` AS schooldetails_Boardtype,
     schooldetails.`Location` AS schooldetails_Location,
     schooldetails.`Phone` AS schooldetails_Phone,
     schooldetails.`Address` AS schooldetails_Address,
     schooldetails.`Additionaldetails` AS schooldetails_Additionaldetails
FROM
     `schooldetails` schooldetails]]>
        </queryString>
        <field name="schooldetails_ID" class="java.lang.Integer"/>
        <field name="schooldetails_Name" class="java.lang.String"/>
        <field name="schooldetails_Boardtype" class="java.lang.String"/>
        <field name="schooldetails_Phone" class="java.lang.String"/>
    </subDataset>
    <queryString>
        <![CDATA[SELECT
     schooldetails.`ID` AS schooldetails_ID,
     schooldetails.`Name` AS schooldetails_Name,
     schooldetails.`Boardtype` AS schooldetails_Boardtype,
     schooldetails.`Location` AS schooldetails_Location,
     schooldetails.`Phone` AS schooldetails_Phone,
     schooldetails.`Address` AS schooldetails_Address,
     schooldetails.`Additionaldetails` AS schooldetails_Additionaldetails
FROM
     `schooldetails` schooldetails]]>
    </queryString>
    <field name="schooldetails_ID" class="java.lang.Integer"/>
    <field name="schooldetails_Name" class="java.lang.String"/>
    <field name="schooldetails_Boardtype" class="java.lang.String"/>
    <field name="schooldetails_Location" class="java.lang.String"/>
    <field name="schooldetails_Phone" class="java.lang.String"/>
    <field name="schooldetails_Address" class="java.lang.String"/>
    <field name="schooldetails_Additionaldetails" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch">
            <staticText>
                <reportElement uuid="e15d9fdb-5a73-421d-8059-3e6d84742a43" x="0" y="0" width="555" height="79"/>
                <textElement textAlignment="Center" verticalAlignment="Middle">
                    <font size="24" isBold="true"/>
                </textElement>
                <text><![CDATA[Sample report 2]]></text>
            </staticText>
        </band>
    </title>
    <detail>
        <band height="114">
            <componentElement>
                <reportElement uuid="0752ad71-0544-4a92-bc06-666619eada15" key="table 1" style="table 1" x="0" y="0" width="360" height="50"/>
                <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="dataset1" uuid="46c3a1a8-1e2b-4ea0-b7ac-5b630657c146">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="99" uuid="b4badcbe-8219-4fcf-978c-b5ff6f2057d0">
                        <jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="09f0cb22-b9b2-499a-9e94-0d9edb96e5f8" x="0" y="0" width="99" height="30"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="14" isBold="true"/>
                                </textElement>
                                <text><![CDATA[School ID]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="0be272c3-3345-48fd-b90a-a0d0df3bc909" x="0" y="0" width="99" height="20"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{schooldetails_ID}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="160" uuid="1f036ef4-d3e4-4113-9084-5530b1e3e8d2">
                        <jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="9ef54b86-c6ac-4f0b-8904-ff82ace55d7c" x="0" y="0" width="160" height="30"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="14" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="6c01ebc8-165d-41da-b632-8b19b67770ac" x="0" y="0" width="160" height="20"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{schooldetails_Name}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="114" uuid="7561e583-3af8-4799-ac88-2a7e8c164bfa">
                        <jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="c500ce42-e32d-4704-9832-52d7413926e3" x="0" y="0" width="114" height="30"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="14" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Board]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="da078d0e-c6fb-4a3d-a0ed-ea12265cf729" x="0" y="0" width="114" height="20"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{schooldetails_Boardtype}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="131" uuid="7842fd3f-e097-4acd-a1ab-a09c0361c23b">
                        <jr:columnHeader style="table 1_CH" height="30" rowSpan="1">
                            <staticText>
                                <reportElement uuid="c0519344-d25a-4ed9-8970-1acf9e4857ed" x="0" y="0" width="131" height="30"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="14" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Phone]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
                            <textField>
                                <reportElement uuid="560916c9-e02a-40c9-a7af-a63d285b900a" x="0" y="0" width="131" height="20"/>
                                <textElement textAlignment="Center" verticalAlignment="Middle">
                                    <font size="12"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{schooldetails_Phone}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

My Question

How can i avoid repetition of table display twice? I want the data to be displayed only one time.

As you see in the above screen shots, I don't want the data to be displayed twice.


回答1:


You have put your table component into the detail band. The detail band is repeated for every record in the dataset. You have two records, so your table is repeated twice; If you had more data, you would get many more repetitions.

You could get rid of the table component completely, putting each columnHeader element from the table into a <columnHeader> band, and each detailCell element into a <detail> band. Doing this should preserve the behaviour of the table component without repeating it. See http://community.jaspersoft.com/wiki/designing-report for an example of this.

Alternatively, you could simply move your table component into a different band that doesn't get repeated (e.g. <summary>).




回答2:


Copy the table component in summary band and delete the detail band.

If you want repeated value in table data then edit your table component in Ireport and select the text field and uncheck the "Print Repeated Values" check box property of a text field.

XML CODE will be like this:-

          </jr:columnHeader>
          <jr:detailCell style="table 1_TD" height="20" rowSpan="1">
             <textField>
                <reportElement uuid="560916c9-e02a-40c9-a7af-a63d285b900a" 
          isPrintRepeatedValues="false" x="0" y="0" width="131" height="20"/>
             <textElement textAlignment="Center" verticalAlignment="Middle">
                 <font size="12"/>
            </textElement>
           <textFieldExpression><![CDATA[$F{schooldetails_Phone}]]>  
           </textFieldExpression>
             </textField>
            </jr:detailCell>
          </jr:column>



回答3:


If your table shows multiple times within List component, uncheck "Print when Detail Overflow" and try. It works for me.



来源:https://stackoverflow.com/questions/15504817/how-to-prevent-repetition-of-data-display-in-report

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!