2

样本报告 - 设计

我的样本报告 - 设计

样本报告 - 预览

在此处输入图像描述

XML 代码文件

<?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>

我的问题

如何避免重复显示表格两次?我希望数据只显示一次。

正如您在上面的屏幕截图中看到的,我不希望数据显示两次。

4

3 回答 3

2

您已将表格组件放入详细信息带中。为数据集中的每条记录重复详细信息带。你有两条记录,所以你的表重复了两次;如果你有更多的数据,你会得到更多的重复。

您可以完全摆脱 table 组件,将 table 中的每个columnHeader元素放入一个<columnHeader>band,并将每个detailCell元素放入一个<detail>band。这样做应该保留表格组件的行为而不重复它。有关此示例,请参见http://community.jaspersoft.com/wiki/designing-report 。

或者,您可以简单地将表格组件移动到不会重复的不同波段(例如<summary>)。

于 2013-03-20T16:26:25.790 回答
1

复制汇总带中的表格组件并删除详细信息带。

如果要在表数据中重复值,则在 Ireport 中编辑表组件并选择文本字段并取消选中文本字段的“打印重复值”复选框属性。

XML 代码将是这样的:-

          </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>
于 2013-03-20T05:10:35.287 回答
0

如果您的表格在列表组件中多次显示,请取消选中“详细信息溢出时打印”并尝试。这个对我有用。

于 2019-01-22T06:29:30.950 回答