如何使用Java代码(Jaspersoft Studio)将报告添加到另一个报告

时间:2017-05-26 14:31:27

标签: java jasper-reports

我有一个报告,而不是填写java代码中的传递参数,现在我想将之前生成的报告传递给另一个大报告。

是一个打印标签的应用程序,最初你可以打印一个标签,但他的另一个功能是在页面中打印多个标签(可以是不同的),所以我试图传递一个报告(单个)报告生成)到另一份报告(更大的报告

这就是我尝试的原因:

/* To fill the map */
private Map fillParameter(){
    Map parametros = new HashMap();

    parametros.put("descripcion", panelDescripcion.getText());
    parametros.put("codigo", panelCodigo.getText());
    parametros.put("lote", panelLote.getText());        
    parametros.put("material", panelMaterial.getText());
    parametros.put("estante", panelEstante.getText());
    parametros.put("referencia", panelReferencia.getText());
    parametros.put("clasificacion", panelAbc.getText());
    parametros.put("cantidad", panelCantidad.getText());
    parametros.put("rif", RIF);

    return parametros;
}

制作子报告:

Map parameters = fillParameter();

JasperReport subReport = (JasperReport) JRLoader.loadObjectFromFile("Etiqueta_M_H.jasper");
JasperPrint jasPrint = JasperFillManager.fillReport(subReport, parameters, new JREmptyDataSource());

parameters = new HashMap();
parameters.put("slot1", jasPrint);

JasperReport mainReport = (JasperReport) JRLoader.loadObjectFromFile("Etiqueta_Multi.jasper");
jasPrint = JasperFillManager.fillReport(mainReport, parameters, new JREmptyDataSource());

在主报告中,我配置了参数名称" slot1"作为JasperPrint,当我运行我的java代码并尝试生成报告时,我得到了这个:

  

线程中的异常" AWT-EventQueue-0" net.sf.jasperreports.engine.JRRuntimeException:不支持的子报表部分类型为net.sf.jasperreports.engine.JasperPrint。

主报告的jrxml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  -->
<!-- 2017-05-26T14:30:38 -->
<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="Blank_Letter" pageWidth="612" pageHeight="792" columnWidth="612" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="70d5ae72-8b3f-4d6d-8c33-bd163aba420b">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
    <parameter name="slot1" class="net.sf.jasperreports.engine.JasperPrint"/>
    <parameter name="slot2" class="net.sf.jasperreports.engine.JasperPrint"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band splitType="Stretch"/>
    </background>
    <summary>
        <band height="791" splitType="Stretch">
            <subreport>
                <reportElement x="10" y="10" width="280" height="150" uuid="fffe225f-aad7-4749-af93-a94b5199288f"/>
                <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                <subreportExpression><![CDATA[$P{slot1}]]></subreportExpression>
            </subreport>
            <subreport>
                <reportElement x="310" y="10" width="280" height="150" uuid="149a74fc-47fd-4b30-b9c2-2824fc2d4a94"/>
                <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                <subreportExpression><![CDATA[$P{slot2}]]></subreportExpression>
            </subreport>
        </band>
    </summary>
</jasperReport>

单个报告的jrxml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  -->
<!-- 2017-05-26T14:47:31 -->
<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="miReporte" pageWidth="283" pageHeight="141" orientation="Landscape" columnWidth="283" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="23fdb837-cf34-425a-adb9-1f28b8b92134">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <property name="com.jaspersoft.studio.unit." value="pixel"/>
    <property name="com.jaspersoft.studio.unit.pageHeight" value="cm"/>
    <property name="com.jaspersoft.studio.unit.pageWidth" value="cm"/>
    <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
    <property name="com.jaspersoft.studio.unit.columnWidth" value="cm"/>
    <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
    <parameter name="descripcion" class="java.lang.String"/>
    <parameter name="codigo" class="java.lang.String">
        <parameterDescription><![CDATA[]]></parameterDescription>
    </parameter>
    <parameter name="material" class="java.lang.String"/>
    <parameter name="cantidad" class="java.lang.String"/>
    <parameter name="estante" class="java.lang.String"/>
    <parameter name="referencia" class="java.lang.String"/>
    <parameter name="clasificacion" class="java.lang.String"/>
    <parameter name="rif" class="java.lang.String"/>
    <parameter name="lote" class="java.lang.String"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <background>
        <band height="141" splitType="Stretch">
            <staticText>
                <reportElement x="7" y="43" width="52" height="15" uuid="1c3583f3-503b-4c9b-997f-746dbd0fce77"/>
                <textElement>
                    <font size="8" isBold="true" isUnderline="false"/>
                </textElement>
                <text><![CDATA[Descripción:]]></text>
            </staticText>
            <staticText>
                <reportElement x="7" y="58" width="52" height="15" uuid="ebd882a9-ee97-42cd-84b1-9ca23a37a8b4"/>
                <textElement>
                    <font size="8" isBold="true" isUnderline="false"/>
                </textElement>
                <text><![CDATA[Material:]]></text>
            </staticText>
            <staticText>
                <reportElement x="7" y="73" width="52" height="15" uuid="19acd15f-3c62-46b5-b2a2-2cb78728bb7a"/>
                <textElement>
                    <font size="8" isBold="true" isUnderline="false"/>
                </textElement>
                <text><![CDATA[Cantidad:]]></text>
            </staticText>
            <staticText>
                <reportElement x="7" y="88" width="52" height="15" uuid="47d380bd-5d99-410d-ae82-ec572eb84467"/>
                <textElement>
                    <font size="8" isBold="true" isUnderline="false"/>
                </textElement>
                <text><![CDATA[Estante:]]></text>
            </staticText>
            <staticText>
                <reportElement x="7" y="103" width="52" height="15" uuid="17e7b87a-5d2c-42cf-9ba0-4a4f39a40e5e"/>
                <textElement>
                    <font size="8" isBold="true" isUnderline="false"/>
                </textElement>
                <text><![CDATA[Referencia:]]></text>
            </staticText>
            <staticText>
                <reportElement x="7" y="118" width="52" height="15" uuid="35d54d85-996b-48d1-964d-3a273318cf08"/>
                <textElement>
                    <font size="8" isBold="true" isUnderline="false"/>
                </textElement>
                <text><![CDATA[Clasificación:]]></text>
            </staticText>
            <textField>
                <reportElement x="59" y="43" width="180" height="15" uuid="9e1c235b-6ab2-4f24-8fdc-1a0b6ddb5868"/>
                <textElement>
                    <font size="8" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{descripcion}]]></textFieldExpression>
            </textField>
            <image>
                <reportElement x="7" y="6" width="126" height="35" uuid="b103e1e6-856e-4205-8f55-a6aeb13a8ee7"/>
                <imageExpression><![CDATA["logo_Burgmann2.png"]]></imageExpression>
            </image>
            <textField>
                <reportElement x="59" y="58" width="100" height="15" uuid="7a0b3313-27ec-4c75-9c34-7014d949f0b1"/>
                <textElement>
                    <font size="8" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{material}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="59" y="73" width="100" height="15" uuid="c6f74174-825e-452b-b223-bb7584208505">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <textElement>
                    <font size="8" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{cantidad}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="59" y="88" width="100" height="15" uuid="fd6b48fa-73e8-4dc3-bccc-fea6068573c0"/>
                <textElement>
                    <font size="8" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{estante}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="59" y="103" width="100" height="15" uuid="1f9a2c94-5c51-4ac8-864e-f1cc829c7235"/>
                <textElement>
                    <font size="8" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{referencia}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="59" y="118" width="100" height="15" uuid="d09347e7-4d56-4e54-a84b-3f2248e030ff"/>
                <textElement>
                    <font size="8" isBold="false"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{clasificacion}]]></textFieldExpression>
            </textField>
            <textField pattern="dd/MM/yyyy">
                <reportElement x="190" y="21" width="66" height="20" uuid="a679b2d4-bb0f-4eac-a736-fca8aa87de9a"/>
                <textElement textAlignment="Right">
                    <font size="8"/>
                </textElement>
                <textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
            </textField>
            <componentElement>
                <reportElement x="159" y="97" width="111" height="42" uuid="0a5dcab5-f2da-4432-9d12-1b022a73ef31">
                    <property name="com.jaspersoft.studio.unit.moduleWidth" value="pixel"/>
                </reportElement>
                <jr:Code128 xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" moduleWidth="1.0">
                    <jr:codeExpression><![CDATA[$P{lote}]]></jr:codeExpression>
                </jr:Code128>
            </componentElement>
            <componentElement>
                <reportElement x="159" y="58" width="111" height="39" uuid="3b3e7af4-d744-47ba-a333-369725dc0c42">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                    <property name="com.jaspersoft.studio.unit.moduleWidth" value="pixel"/>
                </reportElement>
                <jr:Code128 xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" moduleWidth="1.0">
                    <jr:codeExpression><![CDATA[$P{codigo}]]></jr:codeExpression>
                </jr:Code128>
            </componentElement>
            <textField>
                <reportElement x="190" y="6" width="66" height="14" uuid="ecc784c7-d196-4923-93a4-764dcaef71c3"/>
                <textElement textAlignment="Right">
                    <font size="8"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{rif}]]></textFieldExpression>
            </textField>
        </band>
    </background>
</jasperReport>

一些照片:

single report (subreport)

multiple report (master)

0 个答案:

没有答案