本文介绍了如何结合两个已经运作的报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经对子报告进行了一些研究,甚至建立了使用多个子报告的报告。

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 both run and print out (one on first page, one on second page).

我该怎么做?
我是否必须在这些报告中包含每个项目的SQL语句或仅包含导致输入的参数?

我正在使用iReport构建我的自定义jasper报告,

I am using iReport to build my custom jasper reports,

推荐答案

您有2个选项

1。合并报表创建主报表并将报表包含在子报表中。您需要将margin设置为0, whenNoDataType =AllSectionsNoDetail,例如使用 summary band生成新页面对于report2设置 isSummaryNewPage =true。您无需更改任何查询,因为您只需将报表连接传递给报表(子报表)。

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

示例

<?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。在导出期间连接报告

示例(pdf导出与其他类型的导出类似)

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();

这篇关于如何结合两个已经运作的报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 16:34