Jasper Report在jasper表中合并单元格会导致不需要的列

时间:2014-07-05 08:25:23

标签: jasper-reports

我对jasper报道相当新鲜。我需要在jasper表中合并单元格,并且我已经管理了它的一部分。见下图。

enter image description here

你可以看到那里有空单元格。我需要一个单元格而不是多个空单元格。你们能帮助我吗?我被卡住了。我发布了我的jrxml

<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9c6d12ac-438a-4209-b92b-fe8357e9a0ab">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="2"/>
    <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>
    </style>
    <subDataset name="medication" uuid="540773d1-98fb-48a3-9b89-a187c3e37e8a">
        <queryString language="SQL">
            <![CDATA[SELECT m.ID,m.medication_name,d.dose_time FROM medication m
LEFT JOIN dose_time d ON m.ID = d.medication_id;]]>
        </queryString>
        <field name="ID" class="java.lang.Integer">
            <fieldDescription><![CDATA[]]></fieldDescription>
        </field>
        <field name="medication_name" class="java.lang.String">
            <fieldDescription><![CDATA[]]></fieldDescription>
        </field>
        <field name="dose_time" class="java.lang.String">
            <fieldDescription><![CDATA[]]></fieldDescription>
        </field>
        <group name="ID">
            <groupExpression><![CDATA[$F{ID}]]></groupExpression>
        </group>
    </subDataset>
    <queryString>
        <![CDATA[select mdt.ID,mdt.medication_name,dt.dose_time from medication mdt left join dose_time dt on mdt.ID = dt.medication_id;]]>
    </queryString>
    <field name="ID" class="java.lang.Integer">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="medication_name" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="dose_time" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <columnHeader>
        <band height="61" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <componentElement>
                <reportElement uuid="b80b6480-79a3-4c7a-b7e6-73e8df552d6a" key="table" style="table" x="0" y="0" width="555" height="125">
                    <printWhenExpression><![CDATA[$V{REPORT_COUNT} == 1]]></printWhenExpression>
                </reportElement>
                <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="medication" uuid="966ad176-a042-4a9f-b4fe-3c5cf2c43370">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="90" uuid="1674ad29-29a8-47d3-9bf9-fb233d836dcc">
                        <jr:groupFooter groupName="ID">
                            <jr:cell height="0" rowSpan="1"/>
                        </jr:groupFooter>
                        <jr:columnHeader style="table_CH" height="32" rowSpan="1">
                            <staticText>
                                <reportElement uuid="1e2c5349-4cc9-4caf-9d7f-ac34dfbdb1b4" x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[Medication Name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="30" rowSpan="1">
                            <textField>
                                <reportElement uuid="cfeb2bce-6f8d-413c-8f4e-cfbe61cc2d24" style="table_TD" x="0" y="0" width="90" height="30">
                                    <printWhenExpression><![CDATA[$V{ID_COUNT}==1]]></printWhenExpression>
                                </reportElement>
                                <box leftPadding="0">
                                    <pen lineWidth="0.5"/>
                                    <topPen lineWidth="0.5"/>
                                    <leftPen lineWidth="0.5"/>
                                    <bottomPen lineWidth="0.5"/>
                                    <rightPen lineWidth="0.5"/>
                                </box>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{ID}+$F{medication_name}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90" uuid="193e3bc0-bdba-42ec-824a-cb0e7b37b7d1">
                        <jr:columnHeader style="table_CH" height="32" rowSpan="1">
                            <staticText>
                                <reportElement uuid="c165e681-8db2-49af-9046-e3db70bfe0cf" x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[Doses Time]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="30" rowSpan="1">
                            <textField>
                                <reportElement uuid="78fff516-49ab-4e1d-aa06-4c97d48bad0d" x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{dose_time}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

1 个答案:

答案 0 :(得分:1)

我在这里看到两种可能的解决方案:

  1. 通过“药物名称”创建一个组乐队和组,你将有空单元格,但它看起来很酷:)
  2. 使用一些带有函数concat_ws()的SQL功夫来获取与列表相同的字段中的“Doses Time”。
  3. 玩得开心,我希望它有所帮助。