How to combine two already functioning reports?

后端 未结 2 1952
盖世英雄少女心
盖世英雄少女心 2021-01-15 05:45

I have done some research on subreports and have even built report that use several subreports.

I am having an issue combining 2 already made reports so that they bo

相关标签:
2条回答
  • 2021-01-15 05:58

    There is now a third way to concatenate them, especially if the reports have different page size and/or orientation.

    Instead of running them as subreports inside a master report, you can run them as parts inside a book report.

    Please check the /demo/samples/book sample inside the JR Lib project distro package and you can see how 3 reports with different layouts are run together to produce a single file output.

    Also, the /demo/samples/tableofcontents sample relies on this new type of report template, which we call book and is made of parts instead of bands.

    0 讨论(0)
  • 2021-01-15 06:09

    You have 2 options

    1. Combine report creating a main report and include you reports in this as subreport's. You need to set margin to 0, whenNoDataType="AllSectionsNoDetail" and for example use the summary band to generate new page for report2 setting isSummaryNewPage="true". You do not need to change any queries, since you simple pass the report connection to your reports (subreports).

    Example

    <?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="test" pageWidth="612" pageHeight="792" whenNoDataType="AllSectionsNoDetail" columnWidth="612" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isSummaryNewPage="true" uuid="9ac8b394-36b0-409a-8a94-b8147d9c2d20">
        <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
            <defaultValueExpression><![CDATA["C:\\jdd\\projects\\StackTrace\\jasper\\"]]></defaultValueExpression>
        </parameter>
        <title>
            <band height="20">
                <subreport>
                    <reportElement x="0" y="0" width="612" height="20" uuid="e98a3620-58d6-47c1-8c93-6ca3d749b31b"/>
                    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "report1.jasper"]]></subreportExpression>
                </subreport>
            </band>
        </title>
        <summary>
            <band height="20">
                <subreport>
                    <reportElement x="0" y="0" width="612" height="20" uuid="bc0c1758-9ce9-4f6d-a01c-2c77f59ae1fa"/>
                    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "report2.jasper"]]></subreportExpression>
                </subreport>
            </band>
        </summary>
    </jasperReport>
    

    2. Concatenate the report's during exporting

    Example (pdf export is similar with other types of export)

    Map<String, Object> paramMap = new HashMap<String, Object>();
    List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();
    JasperPrint jasperPrint1 = JasperFillManager.fillReport(report1, paramMap);
    jasperPrintList.add(jasperPrint1);
    JasperPrint jasperPrint2 = JasperFillManager.fillReport(report2, paramMap);
    jasperPrintList.add(jasperPrint2);
    
    JRPdfExporter exporter = new JRPdfExporter();
    exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList)); //Set as export input my list with JasperPrint s
    exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("output.pdf")); //or any other out stream
    SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
    exporter.setConfiguration(configuration);
    exporter.exportReport();
    
    0 讨论(0)
提交回复
热议问题