2017-05-01 18 views
-1

Javaプログラムからサブレポート内のサブレポートを使用して、ジャスパーレポートを呼び出す簡単な例はありませんか。このような何か(Generate Jasper report with subreport from java):JasperReports MasterReport-> Subreport-> Subreport

JasperReport jasperMasterReport = JasperCompileManager.compileReport(masterReportSource); 
JasperReport jasperSubReport1 = JasperCompileManager.compileReport(subReportSource1); 
JasperReport jasperSubReport2 = JasperCompileManager.compileReport(subReportSource2); 

Map<String, Object> parameters2 = new HashMap()<String, Object>; 
parameters2.put("subreportParameter2", jasperSubReport2); 

Map<String, Object> parameters1 = new HashMap()<String, Object>; 
parameters1.put("subreportParameter1", JasperFillManager.fillReportToFile(jasperSubReport1, parameters2, connection)); 

JasperFillManager.fillReportToFile(jasperMasterReport, parameters1, connection); 

MasterReport.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-02T10:06: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="MasterReport" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="5adfa1b1-651c-478e-a83b-6230d66dc454"> 
 
\t <property name="com.jaspersoft.studio.data.sql.tables" value=""/> 
 
\t <property name="com.jaspersoft.studio.data.defaultdataadapter" value="OracleJDBC"/> 
 
    <parameter name="subreportParameter1" class="net.sf.jasperreports.engine.JasperReport"/> 
 
\t <queryString language="SQL"> 
 
\t \t <![CDATA[SELECT "PERSON"."ID", 
 
\t "PERSON"."FIRST_NAME", 
 
\t "PERSON"."LAST_NAME" 
 
FROM "PERSON"]]> 
 
\t </queryString> 
 
\t <field name="ID" class="java.math.BigDecimal"/> 
 
\t <field name="FIRST_NAME" class="java.lang.String"/> 
 
\t <field name="LAST_NAME" class="java.lang.String"/> 
 
\t <background> 
 
\t \t <band splitType="Stretch"/> 
 
\t </background> 
 
\t <columnHeader> 
 
\t \t <band height="16" splitType="Stretch"> 
 
\t \t \t <staticText> 
 
\t \t \t \t <reportElement x="0" y="0" width="93" height="16" uuid="cde3f82c-d51e-43ef-a56e-fee3cb853b65"/> 
 
\t \t \t \t <textElement> 
 
\t \t \t \t \t <font isBold="true"/> 
 
\t \t \t \t </textElement> 
 
\t \t \t \t <text><![CDATA[PERSONS:]]></text> 
 
\t \t \t </staticText> 
 
\t \t </band> 
 
\t </columnHeader> 
 
\t <detail> 
 
\t \t <band height="80" splitType="Stretch"> 
 
\t \t \t <textField> 
 
\t \t \t \t <reportElement x="0" y="20" width="30" height="20" uuid="9fbab9bb-55ec-44c0-badb-501a00334fe6"/> 
 
\t \t \t \t <textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression> 
 
\t \t \t </textField> 
 
\t \t \t <staticText> 
 
\t \t \t \t <reportElement x="0" y="0" width="30" height="20" uuid="3c5afed0-442f-41de-9929-abdb8a218981"/> 
 
\t \t \t \t <text><![CDATA[ID]]></text> 
 
\t \t \t </staticText> 
 
\t \t \t <textField> 
 
\t \t \t \t <reportElement x="30" y="20" width="100" height="20" uuid="2561523d-322d-487d-89a2-be44804979ee"/> 
 
\t \t \t \t <textFieldExpression><![CDATA[$F{FIRST_NAME}]]></textFieldExpression> 
 
\t \t \t </textField> 
 
\t \t \t <staticText> 
 
\t \t \t \t <reportElement x="30" y="0" width="100" height="20" uuid="431ac382-603e-47a1-b4df-b9d744041718"/> 
 
\t \t \t \t <text><![CDATA[FIRST NAME]]></text> 
 
\t \t \t </staticText> 
 
\t \t \t <textField> 
 
\t \t \t \t <reportElement x="130" y="20" width="100" height="20" uuid="9b482687-49c6-49f7-b322-ba868e4ce748"/> 
 
\t \t \t \t <textFieldExpression><![CDATA[$F{LAST_NAME}]]></textFieldExpression> 
 
\t \t \t </textField> 
 
\t \t \t <staticText> 
 
\t \t \t \t <reportElement x="130" y="0" width="100" height="20" uuid="4532e6f3-58c0-4c24-aebc-a135309d94ba"/> 
 
\t \t \t \t <text><![CDATA[LAST NAME]]></text> 
 
\t \t \t </staticText> 
 
\t \t \t <subreport> 
 
\t \t \t \t <reportElement x="2" y="40" width="550" height="40" uuid="18ecc4c5-81a1-4ae3-b3f7-3bf10c627be8"/> 
 
\t \t \t \t <subreportParameter name="PERSON_ID"> 
 
\t \t \t \t \t <subreportParameterExpression><![CDATA[$F{ID}]]></subreportParameterExpression> 
 
\t \t \t \t </subreportParameter> 
 
\t \t \t \t <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression> 
 
\t \t \t \t <subreportExpression><![CDATA[$P{subreportParameter1}]]></subreportExpression> 
 
\t \t \t </subreport> 
 
\t \t </band> 
 
\t </detail> 
 
</jasperReport>

Subreport1.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-02T10:11:02 --> 
 
<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="Subreport1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a0096e3a-50c2-49db-ba13-71afb020c425"> 
 
\t <property name="com.jaspersoft.studio.data.sql.tables" value=""/> 
 
\t <property name="com.jaspersoft.studio.data.defaultdataadapter" value="OracleJDBC"/> 
 
\t <parameter name="PERSON_ID" class="java.math.BigDecimal"/> 
 
    <parameter name="subreportParameter2" class="net.sf.jasperreports.engine.JasperReport"/> 
 
\t <queryString language="SQL"> 
 
\t \t <![CDATA[SELECT "PHONE"."ID", 
 
\t "PHONE"."PARENT_ID", 
 
\t "PHONE"."PHONE_NUMBER" 
 
FROM "PHONE" 
 
WHERE "PHONE"."PARENT_ID" = $P{PERSON_ID} ]]> 
 
\t </queryString> 
 
\t <field name="ID" class="java.math.BigDecimal"/> 
 
\t <field name="PARENT_ID" class="java.math.BigDecimal"/> 
 
\t <field name="PHONE_NUMBER" class="java.lang.String"/> 
 
\t <background> 
 
\t \t <band splitType="Stretch"/> 
 
\t </background> 
 
\t <columnHeader> 
 
\t \t <band height="20" splitType="Stretch"> 
 
\t \t \t <staticText> 
 
\t \t \t \t <reportElement x="0" y="0" width="100" height="20" uuid="26c75f7b-f80c-41ca-a3fc-eb3317026efd"/> 
 
\t \t \t \t <textElement> 
 
\t \t \t \t \t <font isBold="true"/> 
 
\t \t \t \t </textElement> 
 
\t \t \t \t <text><![CDATA[PHONES:]]></text> 
 
\t \t \t </staticText> 
 
\t \t </band> 
 
\t </columnHeader> 
 
\t <detail> 
 
\t \t <band height="70" splitType="Stretch"> 
 
\t \t \t <textField> 
 
\t \t \t \t <reportElement x="90" y="0" width="454" height="20" uuid="76669766-73b0-47f1-bfff-9337428a4776"/> 
 
\t \t \t \t <textFieldExpression><![CDATA[$F{PHONE_NUMBER}]]></textFieldExpression> 
 
\t \t \t </textField> 
 
\t \t \t <staticText> 
 
\t \t \t \t <reportElement x="0" y="0" width="90" height="20" uuid="f925e71b-16fe-42ae-8895-143fb886eb63"/> 
 
\t \t \t \t <text><![CDATA[PHONE NUMBER:]]></text> 
 
\t \t \t </staticText> 
 
\t \t \t <subreport> 
 
\t \t \t \t <reportElement x="0" y="30" width="544" height="40" uuid="029f8258-5205-4e91-ae08-e8d8ec55f5e9"/> 
 
\t \t \t \t <subreportParameter name="PHONE_ID"> 
 
\t \t \t \t \t <subreportParameterExpression><![CDATA[$F{ID}]]></subreportParameterExpression> 
 
\t \t \t \t </subreportParameter> 
 
\t \t \t \t <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression> 
 
\t \t \t \t <subreportExpression><![CDATA[$P{subreportParameter2}]]></subreportExpression> 
 
\t \t \t </subreport> 
 
\t \t </band> 
 
\t </detail> 
 
</jasperReport>

Subreport2.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-02T10:13:15 --> 
 
<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="Subreport2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9bd68d39-b94b-4e26-94ea-e0dc1e55f226"> 
 
\t <property name="com.jaspersoft.studio.data.sql.tables" value=""/> 
 
\t <property name="com.jaspersoft.studio.data.defaultdataadapter" value="OracleJDBC"/> 
 
\t <parameter name="PHONE_ID" class="java.math.BigDecimal"/> 
 
\t <queryString language="SQL"> 
 
\t \t <![CDATA[SELECT "CONTACT_LOG"."ID", 
 
\t "CONTACT_LOG"."R_PHONE_ID", 
 
\t "CONTACT_LOG"."DSC" 
 
FROM "CONTACT_LOG" 
 
WHERE "CONTACT_LOG"."R_PHONE_ID" = $P{PHONE_ID}]]> 
 
\t </queryString> 
 
\t <field name="ID" class="java.math.BigDecimal"/> 
 
\t <field name="R_PHONE_ID" class="java.math.BigDecimal"/> 
 
\t <field name="DSC" class="java.lang.String"/> 
 
\t <background> 
 
\t \t <band splitType="Stretch"/> 
 
\t </background> 
 
\t <columnHeader> 
 
\t \t <band height="15" splitType="Stretch"> 
 
\t \t \t <staticText> 
 
\t \t \t \t <reportElement x="0" y="0" width="100" height="15" uuid="0779105f-7c86-4541-906f-ea473cdc3ff5"/> 
 
\t \t \t \t <textElement> 
 
\t \t \t \t \t <font isBold="true"/> 
 
\t \t \t \t </textElement> 
 
\t \t \t \t <text><![CDATA[CONTACTS:]]></text> 
 
\t \t \t </staticText> 
 
\t \t </band> 
 
\t </columnHeader> 
 
\t <detail> 
 
\t \t <band height="30" splitType="Stretch"> 
 
\t \t \t <textField> 
 
\t \t \t \t <reportElement x="102" y="0" width="448" height="30" uuid="67919643-f890-4121-ac18-59f87b0752f3"/> 
 
\t \t \t \t <textFieldExpression><![CDATA[$F{DSC}]]></textFieldExpression> 
 
\t \t \t </textField> 
 
\t \t \t <staticText> 
 
\t \t \t \t <reportElement x="2" y="0" width="100" height="30" uuid="7c3824f0-41ff-4e53-8278-dcd0e535efd4"/> 
 
\t \t \t \t <text><![CDATA[COMMENT:]]></text> 
 
\t \t \t </staticText> 
 
\t \t </band> 
 
\t </detail> 
 
</jasperReport>

感謝。

答えて

0

メインレポートパラメータとしてサブレポートパスを渡し、このようなサブレポートの番号を取得できます。

  String file = /pathToMainReport/name.jrxml; 
      String subreport1 = /pathToSubReport/name1.jasper; 
      String subreport2 = /pathToSubReport/name2.jasper;  

      JasperReport jreport = JasperCompileManager.compileReport(file); 


      Map<String, Object> map = new HashMap<String, Object>(); 

      map.put("SUBREPORT_DIR1", subreport1); 
      map.put("SUBREPORT_DIR2", subreport2); 

      JasperPrint jprint = JasperFillManager.fillReport(jreport, map, connection); 
+0

おかげで、あなたの答えのためのpariad neupane、私はあなたが私の一例を示したと考え、マスターレポート内の2つのサブレポート:((MasterReport <-> Subreport1)及び(MasterReport <-> Subreport2))が、私の問題は難しいです:( MasterReport <->サブレポート1 <->サブレポート2)。 –

+0

まあ、このブログを参照してください。 http://hamroblog-sristi.blogspot.com/2011/04/ireport-call-to-subreport-inside.html –

+0

ありがとうございます、私はそれをやろうとします。 –

関連する問題