首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SubReport未显示

SubReport未显示
EN

Stack Overflow用户
提问于 2016-01-18 22:35:54
回答 1查看 2.3K关注 0票数 4

我想要创建一个简单的Jasper报告,带有子报表,但我无法使它工作。

例如,我有两个简单的报告。

test1.jrxml

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2016-01-18T23:29:14 -->
<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="test1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="553ce57f-5ea7-48e5-8eaa-dcfecf31880a">
    <queryString>
        <![CDATA[select dummy from dual]]>
    </queryString>
    <field name="dummy" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <staticText>
                <reportElement x="89" y="0" width="100" height="30" uuid="04f9b63d-265b-45f0-a249-41464df6b4c0"/>
                <text><![CDATA[x]]></text>
            </staticText>
            <staticText>
                <reportElement x="227" y="0" width="100" height="30" uuid="0c7db454-653c-4dcf-af94-a0f1c9962b91"/>
                <text><![CDATA[x]]></text>
            </staticText>
            <staticText>
                <reportElement x="352" y="0" width="100" height="30" uuid="7ad861d5-74ba-49e9-95c7-4cd01d184dbe"/>
                <text><![CDATA[x]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="257" splitType="Stretch">
            <textField>
                <reportElement x="89" y="66" width="100" height="30" uuid="4099071d-8bfc-4e61-a697-af078ccb626a"/>
                <textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="227" y="68" width="100" height="30" uuid="a955ca4e-aecd-48c3-8b7c-face6295b879"/>
                <textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="352" y="65" width="100" height="30" uuid="5a998443-ae4f-457d-a565-67b4f3405951"/>
                <textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
            </textField>
            <subreport>
                <reportElement x="555" y="57" width="200" height="200" uuid="d6eada20-a566-4ba5-ab51-9d6ea0b4dfd9"/>
                <parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
                <subreportParameter name="a">
                    <subreportParameterExpression><![CDATA[12]]></subreportParameterExpression>
                </subreportParameter>
                <subreportExpression><![CDATA["test4.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

test4.jrxml

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
<!-- 2016-01-18T23:27:56 -->
<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="test4" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c55e71d8-6eb9-4f20-9263-c50c295fa0d1">
    <parameter name="a" class="java.lang.String"/>
    <queryString>
        <![CDATA[select dummy from dual where 1=1]]>
    </queryString>
    <field name="dummy" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="79" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="35" splitType="Stretch"/>
    </pageHeader>
    <columnHeader>
        <band height="61" splitType="Stretch">
            <staticText>
                <reportElement x="364" y="0" width="100" height="30" uuid="1d48df0f-3f4c-489f-b479-e981b2727590"/>
                <text><![CDATA[b]]></text>
            </staticText>
            <staticText>
                <reportElement x="478" y="0" width="100" height="30" uuid="397b1c60-fe4d-4f41-a7a4-7c585a57ac15"/>
                <text><![CDATA[a]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <staticText>
                <reportElement x="239" y="58" width="100" height="30" uuid="5b5c86c0-1b1b-44d3-87cb-2ad2782a3408"/>
                <text><![CDATA[test4]]></text>
            </staticText>
            <textField>
                <reportElement x="364" y="66" width="100" height="30" uuid="d3217648-88a1-4d88-b2b0-7f7cc4e598c6"/>
                <textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="478" y="47" width="100" height="30" uuid="f2c6bfb9-ee73-4928-8ce4-0a83060d0801"/>
                <textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

选择提供一个结果( DB是Oracle),但子报告在test1.jrxml生成的repport中不可见。但是报告的末尾是一个全新的空白页。

你能告诉我这个例子有什么问题吗?我尝试了很多东西(子报表中的默认值,当No Data =所有部分,subreport的头中没有细节设置,还有很多东西,我不记得了),但是没有任何帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-19 09:24:05

在您的示例中,我可以看到两个问题:

  1. 您需要将绝对路径传递给子报表(这通常是通过参数完成的,以便可以在运行时进行控制)
代码语言:javascript
复制
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA["C:\\jdd\\projects\\StackTrace\\jasper\\"]]></defaultValueExpression>
</parameter>

<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "test4.jasper"]]></subreportExpression>
  1. 您需要将报表连接传递到子报表。
代码语言:javascript
复制
<subreport>
    <reportElement x="555" y="57" width="200" height="200" uuid="d6eada20-a566-4ba5-ab51-9d6ea0b4dfd9"/>
    <parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
    <subreportParameter name="a">
        <subreportParameterExpression><![CDATA[12]]></subreportParameterExpression>
    </subreportParameter>
    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
    <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "test4.jasper"]]></subreportExpression>
</subreport>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34865347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档