我有一个主要报告,其中来自Map对象的java代码参数。 在主报表中包含一个子报表并尝试传递主报表参数。
主报告和子报告单独工作正常但主报告未显示子报告。
Invoice.jrxml(主报告):
<?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="ma" pageWidth="683" pageHeight="899" columnWidth="643" leftMargin="20" rightMargin="20" topMargin="1" bottomMargin="1" isSummaryNewPage="true" isSummaryWithPageHeaderAndFooter="true" uuid="51ff5174-9cb9-4d22-8e11-cd3fe9392bbd">
<property name="net.sf.jasperreports.awt.ignore.missing.font" value="true"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="filePath" class="java.lang.String"/>
<parameter name="imagePath" class="java.lang.String"/>
<parameter name="orderId" class="java.lang.String"/>
<parameter name="orderNum" class="java.lang.String"/>
<parameter name="orderDate" class="java.util.Date"/>
<parameter name="billingAddress" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<pageHeader>
<band height="121">
<image>
<reportElement x="8" y="0" width="314" height="50" uuid="c072a055-ead7-4e63-b87f-3d7163cf2f2b"/>
<imageExpression><![CDATA[$P{imagePath}]]></imageExpression>
</image>
<textField>
<reportElement x="240" y="37" width="166" height="20" uuid="7619dfad-f0f5-4c80-9f73-625cfb24d1a5"/>
<textElement textAlignment="Center">
<font size="14" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["INVOICE"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="17" y="61" width="68" height="20" uuid="9d49ad56-14a9-4214-a615-3ce706cdcb0f"/>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["ORDER NO. "]]></textFieldExpression>
</textField>
<textField>
<reportElement x="85" y="61" width="7" height="20" uuid="8d44e405-3d27-421f-bd07-eeac5d84699c"/>
<textElement>
<font fontName="Times New Roman" pdfFontName="Times-Roman"/>
</textElement>
<textFieldExpression><![CDATA[":"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="92" y="61" width="100" height="20" uuid="5eee8a2d-9c15-4c36-887b-9baf8009901e"/>
<textFieldExpression><![CDATA[$P{orderNum}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="488" y="61" width="79" height="20" uuid="d6eba4a3-4349-4220-ac2a-8e7ac45866d2"/>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["INVOICE DATE"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="568" y="61" width="7" height="20" uuid="933fae5b-6850-4620-9860-609fb4f3ae0e"/>
<textElement>
<font fontName="Times New Roman" pdfFontName="Times-Roman"/>
</textElement>
<textFieldExpression><![CDATA[":"]]></textFieldExpression>
</textField>
<textField pattern="dd-MMM-yyyy">
<reportElement x="575" y="61" width="70" height="20" uuid="94a17726-82c9-4068-a508-faa9669bb867"/>
<textFieldExpression><![CDATA[new Date()]]></textFieldExpression>
</textField>
<textField>
<reportElement x="17" y="81" width="68" height="20" uuid="8193c234-a847-4db7-9f77-86cb8b7ea06e"/>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["PLACED ON "]]></textFieldExpression>
</textField>
<textField>
<reportElement x="85" y="81" width="7" height="20" uuid="b4226f3c-6c85-4a66-a86f-25f846a0c0ff"/>
<textElement>
<font fontName="Times New Roman" pdfFontName="Times-Roman"/>
</textElement>
<textFieldExpression><![CDATA[":"]]></textFieldExpression>
</textField>
<textField pattern="dd-MMM-yyyy">
<reportElement x="92" y="81" width="100" height="20" uuid="23599627-a12c-4409-bf59-690182c93265"/>
<textFieldExpression><![CDATA[$P{orderDate}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="488" y="81" width="79" height="20" uuid="c5382e3e-b4ae-45ca-8ed3-d78fc180730b"/>
<textElement>
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["INVOICE NO. "]]></textFieldExpression>
</textField>
<textField>
<reportElement x="568" y="81" width="7" height="20" uuid="4c26ae03-6d88-45c6-83cd-e8144a428813"/>
<textElement>
<font fontName="Times New Roman" pdfFontName="Times-Roman"/>
</textElement>
<textFieldExpression><![CDATA[":"]]></textFieldExpression>
</textField>
<line>
<reportElement x="15" y="106" width="619" height="1" uuid="f1d3c700-6cd0-4e6f-9482-ac0de6899d6c"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
</band>
</pageHeader>
<detail>
<band height="54" splitType="Stretch">
<subreport isUsingCache="false">
<reportElement x="0" y="0" width="200" height="54" uuid="0b04fdb2-f4bb-4db2-935a-be96d92fa8db"/>
<subreportParameter name="billingAddress">
<subreportParameterExpression><![CDATA[$P{billingAddress}]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA[$P{filePath} + "/BillingVenueSubReport.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
<pageFooter>
<band height="67">
<textField>
<reportElement x="539" y="47" width="86" height="20" uuid="071f6609-ce04-405d-b993-ad0e89d95919"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="626" y="47" width="25" height="20" uuid="abb1c879-f261-4d0f-ba1b-7f0569d1c947"/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField pattern="EEE,yyy,MMMMM,dd hh:mm aaa">
<reportElement x="67" y="47" width="168" height="20" uuid="36b23a16-1717-472c-96d7-a6f250137920"/>
<textFieldExpression><![CDATA[new Date()]]></textFieldExpression>
</textField>
<textField>
<reportElement x="9" y="3" width="634" height="46" uuid="ef43f479-905b-4e70-8410-3641b2ef7b73"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["#72/4, First Floor, Near Gokula Towers, Dr. MS Ramaiah Rd, HMS Layout,Gokula Extension Mathikere, Bengaluru, Karnataka 560054, Service Tax #AAICP5558PSD001, Service Tax Category Supply of Tangible Goods Service, PAN No.AAICP5558P, CIN:U74900KA2016PTC086666 Tel: 080 4114566 Web: www.powersparrow.com © POWERSPARROW INDIA PRIVATE LIMITED"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="13" y="48" width="61" height="19" uuid="cc0b3cef-159f-4688-8325-3dfac9cb8631"/>
<textElement>
<font fontName="Times New Roman" pdfFontName="Times-Roman"/>
</textElement>
<textFieldExpression><![CDATA["Printed On: "]]></textFieldExpression>
</textField>
<line>
<reportElement x="11" y="3" width="624" height="1" uuid="f2aae4f8-1a16-4563-9ecd-38a610a3e51b"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
</band>
</pageFooter>
<lastPageFooter>
<band height="108">
<textField>
<reportElement x="542" y="0" width="101" height="24" uuid="d45e931d-45ef-42ac-b026-79d35954b03f"/>
<textElement verticalAlignment="Bottom">
<font size="12" isItalic="true"/>
</textElement>
<textFieldExpression><![CDATA["Thank You !"]]></textFieldExpression>
</textField>
<textField pattern="EEE,yyy,MMMMM,dd hh:mm aaa">
<reportElement x="68" y="88" width="168" height="20" uuid="547654f3-c4ff-45f7-8ad1-9f8d70b5b454"/>
<textFieldExpression><![CDATA[new Date()]]></textFieldExpression>
</textField>
<textField>
<reportElement x="10" y="44" width="634" height="46" uuid="7748c51f-0b9e-4d10-b80d-c44bb9c16523"/>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<textFieldExpression><![CDATA["#72/4, First Floor, Near Gokula Towers, Dr. MS Ramaiah Rd, HMS Layout,Gokula Extension Mathikere, Bengaluru, Karnataka 560054, Service Tax #AAICP5558PSD001, Service Tax Category Supply of Tangible Goods Service, PAN No.AAICP5558P, CIN:U74900KA2016PTC086666 Tel: 080 4114566 Web: www.powersparrow.com © POWERSPARROW INDIA PRIVATE LIMITED"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="14" y="89" width="61" height="19" uuid="6d2b3804-3f20-4b5b-b7e4-04064df35dac"/>
<textElement>
<font fontName="Times New Roman" pdfFontName="Times-Roman"/>
</textElement>
<textFieldExpression><![CDATA["Printed On: "]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="627" y="88" width="25" height="20" uuid="b8c448b9-aebb-4708-ae0a-e169d30131ec"/>
<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="540" y="88" width="86" height="20" uuid="73bad185-9ff2-42f1-9a05-fc18a23bb48b"/>
<textElement textAlignment="Right"/>
<textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
</textField>
<line>
<reportElement x="12" y="44" width="624" height="1" uuid="d8b89ce1-6581-4ce6-abf0-55fb079286e6"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</line>
<textField>
<reportElement x="527" y="24" width="118" height="20" uuid="2a56862b-8300-460b-afb6-367fb031d6fe"/>
<textElement textAlignment="Center" verticalAlignment="Top">
<font isItalic="true"/>
</textElement>
<textFieldExpression><![CDATA["For Your Business"]]></textFieldExpression>
</textField>
</band>
</lastPageFooter>
</jasperReport>
billingVenuSubReport.xml(子报告):
<?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="MultipleReport" pageWidth="629" pageHeight="842" columnWidth="629" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="898b61ea-06d8-443b-9332-6c4e1a9cde27">
<property name="net.sf.jasperreports.awt.ignore.missing.font" value="true"/>
<parameter name="billingAddress" class="java.lang.String"/>
<queryString>
<![CDATA[]]>
</queryString>
<title>
<band height="74">
<rectangle>
<reportElement stretchType="RelativeToBandHeight" x="18" y="0" width="187" height="73" isRemoveLineWhenBlank="true" uuid="7b23f2bd-0dcb-45a2-95e4-30db17995322"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</rectangle>
<rectangle>
<reportElement stretchType="RelativeToBandHeight" x="205" y="0" width="193" height="73" isRemoveLineWhenBlank="true" uuid="b7f856b6-6047-4458-add5-5c3999db8276"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</rectangle>
<rectangle>
<reportElement stretchType="RelativeToBandHeight" x="398" y="0" width="228" height="73" isRemoveLineWhenBlank="true" uuid="a38c9204-bd4d-4272-a437-bdaadb824973"/>
<graphicElement>
<pen lineWidth="0.5"/>
</graphicElement>
</rectangle>
<textField>
<reportElement isPrintRepeatedValues="false" x="21" y="0" width="151" height="14" uuid="3f7fecf6-3f08-458a-b64d-0b660661385e"/>
<textElement>
<font fontName="Times New Roman" isBold="true" pdfFontName="Times-Bold"/>
</textElement>
<textFieldExpression><![CDATA["BILLING ADDRESS"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="21" y="13" width="151" height="13" uuid="62f86f45-e16b-4e0b-ae88-658b3bdf5c57"/>
<textElement>
<font fontName="Times New Roman" size="9" pdfFontName="Times-Roman"/>
</textElement>
<textFieldExpression><![CDATA[$P{billingAddress}]]></textFieldExpression>
</textField>
</band>
</title>
</jasperReport>
Java代码:
Map<String,Object> reportParameters = new HashMap<>();
URL jrxmlUrl = this.getClass().getResource("/jrxml");
String filePath= jrxmlUrl.getPath();
String imagePath= filePath+"/logo.jpg";
reportParameters.put("filePath", filePath);
reportParameters.put("imagePath", imagePath);
setCommonParameters(reportDTO, orderInvoiceDetail, reportParameters);
setBillingLocationParameter(orderInvoiceDetail, reportParameters);
String invoiceFileName = "invoice_"+orderId+"_"+orderItemId+".pdf";
JasperPrint jasperPrint = JasperFillManager.fillReport(filePath+"/Invoice.jasper", reportParameters, new JREmptyDataSource());
Path invoiceFilePath = storageService.getFilePath(FileCategoryEnum.INVOICE, orgId, invoiceFileName);
Resource resource = new UrlResource(invoiceFilePath.toUri());
if(resource.exists()) {
resource.getFile().delete();
}
OutputStream outputStream = new FileOutputStream(invoiceFilePath.toFile());
JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream);
outputStream.flush();
outputStream.close();
非常感谢任何帮助。
答案 0 :(得分:0)
子报表没有数据源,也没有生成任何输出(默认情况下)。
你可以做(至少)两件事。
将JREmptyDataSource
传递给子报告(就像您在Java代码中对主报告所做的那样):
<subreport isUsingCache="false">
<reportElement x="0" y="0" width="200" height="54" uuid="0b04fdb2-f4bb-4db2-935a-be96d92fa8db"/>
<subreportParameter name="billingAddress">
<subreportParameterExpression><![CDATA[$P{billingAddress}]]></subreportParameterExpression>
</subreportParameter>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{filePath} + "/BillingVenueSubReport.jasper"]]></subreportExpression>
</subreport>
在子报告中设置whenNoDataType="AllSectionsNoDetail"
(<jasperReport>
级别)。这将导致子报表在没有数据时打印除细节带之外的所有波段(在您的情况下,因为您的子报表仅使用标题波段)。