忽略仅返回空白值的子报表

时间:2019-10-15 18:42:31

标签: jasper-reports subreport

我使用TIBCO Jaspersoft Studio创建了一个包含三个子报表的主报表。当每个子报表返回至少一个非空白值时,主报表将按预期工作。当仅一个子报表仅返回空白值时,由于声明为空,因此不会生成预览的文档

为了避免返回值设置为null的问题,请在每个字段的属性框中将所有文本字段设置为“如果NULL则空白”

主报告的三个子报告和文本字段在其.jrxml中定义如下

<pageHeader>
    <band height="113">
        <subreport>
            <reportElement x="0" y="0" width="538" height="110" uuid="4fbe1f2c-d89c-4217-8e15-65439f745ef4"/>
            <subreportParameter name="encounterID">
                <subreportParameterExpression><![CDATA[$P{encounterID}]]></subreportParameterExpression>
                </subreportParameter>
                <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                <subreportExpression><![CDATA["EncounterRpt_Top.jasper"]]></subreportExpression>
        </subreport>
    </band>
</pageHeader>
<detail>
    <band height="98">
        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.spreadsheet.SpreadsheetLayout"/>
        <textField isStretchWithOverflow="true">
            <reportElement stretchType="ElementGroupHeight" x="0" y="0" width="538" height="98" uuid="47bd7997-b492-4a77-bb01-3e6303af9e58"/>
            <textElement textAlignment="Justified" markup="html"/>
            <textFieldExpression><![CDATA[$F{dtcmts}]]></textFieldExpression>
        </textField>
        <break>
            <reportElement x="0" y="0" width="97" height="1" isPrintWhenDetailOverflows="true" uuid="4b468d03-feac-4678-b3ac-49a88b154e8a"/>
        </break>
    </band>
    <band height="101">
        <subreport>
            <reportElement x="0" y="0" width="538" height="100" uuid="7e83e8e9-3e68-4897-b01d-51c6f8f78acb"/>
            <subreportParameter name="encounterID">
                <subreportParameterExpression><![CDATA[$P{encounterID}]]></subreportParameterExpression>
            </subreportParameter>
            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
            <subreportExpression><![CDATA["VitalSignsRpt.jasper"]]></subreportExpression>
        </subreport>
    </band>
    <band height="102">
        <subreport>
            <reportElement x="0" y="0" width="538" height="100" uuid="7e83e8e9-3e68-4897-b01d-51c6f8f78acb"/>
            <subreportParameter name="encounterID">
                <subreportParameterExpression><![CDATA[$P{encounterID}]]></subreportParameterExpression>
            </subreportParameter>
            <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
            <subreportExpression><![CDATA["LocationSurveyRpt.jasper"]]></subreportExpression>
        </subreport>
    </band>
</detail>

最后一个子报表的字段定义如下(注意第二行上的isBlankWhenNull =“ true”)

...
<style name="Data Style" mode="Transparent" forecolor="#000000" backcolor="#FFFFFF" hTextAlign="Center" vTextAlign="Middle" 
    pattern="" isBlankWhenNull="true" fontSize="12" isBold="false">
        <!-- Data Style is used by the details container -->
</style>
<style name="Header Style" mode="Opaque" forecolor="#FFFFFF" backcolor="#1976D2" hTextAlign="Center" vTextAlign="Middle" 
    pattern="" fontSize="13" isBold="true">
        <!-- Header Style is used by the detail container -->
</style>
<parameter name="encounterID" class="java.lang.Integer" evaluationTime="Early">
    <!-- used by the query immediately below -->
</parameter>
<queryString>
        <![CDATA[SELECT sv.survey_name as svnm, ct.composite_score as ctcs, ct.secondary_score as ctss, 
        ct.subscores as ctsb, ct.encounter_id as ctei FROM client_surveys ct 
        INNER JOIN surveys sv ON ct.survey_id = sv.survey_id
        WHERE ct.encounter_id = $P{encounterID}]]>
</queryString>
<field>
        <!-- Declarations of the field tags -->
</field>
<background>
    <band splitType="Stretch"/>
</background>
<pageHeader>
        <!-- Printing of the report's name is defined here -->
</pageHeader>
<columnHeader>
        <!-- Column names are printed here -->
    <band height="30" splitType="Stretch">
        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.spreadsheet.SpreadsheetLayout"/>
        <staticText>
            <reportElement style="Header Style" x="0" y="0" width="120" height="30" uuid="c10584b8-98bf-4e36-bf59-3324afe8dbb9"/>
            <text><![CDATA[Survey Name]]></text>
        </staticText>
        <staticText>
            <reportElement style="Header Style" x="120" y="0" width="140" height="30" uuid="331f69f5-9a55-4567-8dab-4371491e78d2"/>
            <text><![CDATA[Composite Score]]></text>
        </staticText>
        <staticText>
            <reportElement style="Header Style" x="260" y="0" width="140" height="30" uuid="a75588dc-be3f-4359-b2ac-84397653fd93"/>
            <text><![CDATA[Secondary Score]]></text>
        </staticText>
        <staticText>
            <reportElement style="Header Style" x="400" y="0" width="130" height="30" uuid="50726655-fc62-4496-b1a3-75c08d0bc24e"/>
            <text><![CDATA[Subscores]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
        <!-- row values, if any, are printed here -->
    <band height="30" splitType="Stretch">
        <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.spreadsheet.SpreadsheetLayout"/>
        <textField>
            <reportElement style="Data Style" x="0" y="0" width="120" height="30" uuid="f15948f3-599a-4e73-9b42-00880da0a64e"/>
            <textFieldExpression><![CDATA[$F{svnm}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement style="Data Style" x="120" y="0" width="140" height="30" uuid="42d3b12d-73e1-4fd9-ac9e-e2b5469e1157"/>
            <textFieldExpression><![CDATA[$F{ctcs}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement style="Data Style" x="260" y="0" width="140" height="30" uuid="3024d30f-829d-42fa-8adc-2e9f7ebb26e5"/>
            <textFieldExpression><![CDATA[$F{ctss}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement style="Data Style" x="400" y="0" width="130" height="30" uuid="bff07050-bdb8-4760-8ebf-3c25dbb9b1ce"/>
            <textFieldExpression><![CDATA[$F{ctsb}]]></textFieldExpression>
        </textField>
    </band>
</detail>
...

如开头所述,我希望每次发送请求时都打印我的主报告,而不管子报告返回的值如何。如果子报表仅返回空白值,则应从主报表中省略该报表。现在,即使子报表返回了空白值,即使其他报表返回了信息,主报表也被声明为空

是否有一个标签指示主报表在子报表仅返回空白值时忽略子报表?也许是“ ignoreWhenBlank”或其他名称?如果没有,我该怎么办

0 个答案:

没有答案