How to combine two already functioning reports?

后端 未结 2 1954
盖世英雄少女心
盖世英雄少女心 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 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

    
    
        
            
        
        
            <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>
        
        
            
                
                    
                    
                    
                
            
        
    
    

    2. Concatenate the report's during exporting

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

    Map paramMap = new HashMap();
    List jasperPrintList = new ArrayList();
    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();
    

提交回复
热议问题